【问题标题】:Yamllint Indentation Warning on Valid Ansible code有效 Ansible 代码上的 Yamllint 缩进警告
【发布时间】:2017-11-21 16:16:13
【问题描述】:

我的剧本中有以下任务:

    - name: gather os specific variables
      include_vars: "{{ item }}"
      with_first_found:
        - files:
          - "{{ ansible_distro }}-{{
                ansible_distribution_version|lower|replace('/', '_') }}.yml"
          - "{{ ansible_distro }}-{{ ansible_distribution_release }}.yml"
          - "{{ ansible_distro }}-{{
                ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
          - "{{ ansible_distro }}.yml"
          - "{{ ansible_os_family|lower }}.yml"
          paths:
          - ../vars
          skip: true

截至https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/lookup/first_found.py,这是正确的。

Yamllint 给我以下错误:

  10:7      warning  wrong indentation: expected 8 but found 6  (indentation)
  18:7      warning  wrong indentation: expected 8 but found 6  (indentation)

为什么 Yamllint 会在这里抱怨,我该如何纠正它以使其符合同时仍然是有效的 Ansible 任务?

【问题讨论】:

    标签: ansible yaml


    【解决方案1】:

    解析正确,但不足以让 linter 通过。

    添加两个空格以获得更好的外观:

      with_first_found:
        - files:
            - "{{ ansible_distro }}-{{
          ^^ here
    

    这里:

          paths:
            - ../vars
          ^^
    

    【讨论】:

    • 我们实际上已经改变了这一点——删除了这两个额外的空格。用python的yamllintthe config isindent-sequences: false
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    相关资源
    最近更新 更多