Ansible lint标签
这篇文章是 Ansible 严格检查规则的附属文,属于 2022 年《Ansible 之旅》第三篇。
在Ansible lint的规则中,有两种主要分类,即标签和配置文件(Profile)。本次将对标签进行解释说明。
标签列表
可以使用 ansible-lint –list-tags 命令查看标签。
- 
- command-shell
 
- 
- core
 
- 
- deprecations
 
- 
- experimental
 
- 
- formatting
 
- 
- idempotency
 
- 
- idiom
 
- 
- metadata
 
- 
- opt-in
 
- 
- risk
 
- 
- security
 
- 
- syntax
 
- 
- unpredictability
 
- 
- unskippable
 
- yaml
ansible-lint --list-tags
# List of tags and rules they cover
command-shell:  # Specific to use of command and shell modules
  - command-instead-of-module
  - command-instead-of-shell
  - deprecated-command-syntax
  - inline-env-var
  - no-changed-when
  - risky-shell-pipe
core:  # Related to internal implementation of the linter
  - internal-error
  - load-failure
  - parser-error
  - syntax-check
  - warning
  - schema
deprecations:  # Indicate use of features that are removed from Ansible
  - deprecated-bare-vars
  - deprecated-command-syntax
  - deprecated-local-action
  - deprecated-module
  - no-jinja-when
  - role-name
experimental:  # Newly introduced rules, by default triggering only warnings
  - warning
  - avoid-implicit
  - galaxy
  - ignore-errors
  - key-order
  - no-free-form
  - no-log-password
  - no-prompting
  - only-builtins
  - risky-file-permissions
  - run-once
  - schema
  - var-naming
formatting:  # Related to code-style
  - yaml
  - fqcn
  - jinja
  - key-order
  - no-tabs
  - playbook-extension
  - risky-octal
idempotency:  # Possible indication that consequent runs would produce different results
  - latest
  - no-changed-when
  - package-latest
idiom:  # Anti-pattern detected, likely to cause undesired behavior
  - command-instead-of-module
  - command-instead-of-shell
  - empty-string-compare
  - inline-env-var
  - literal-compare
  - loop-var-prefix
  - name
  - no-handler
  - no-relative-paths
  - run-once
  - var-naming
metadata:  # Invalid metadata, likely related to galaxy, collections or roles
  - galaxy
  - meta-incorrect
  - meta-no-info
  - meta-no-tags
  - meta-video-links
  - role-name
opt-in:  # Rules that are not used unless manually added to `enable_list`
  - empty-string-compare
  - galaxy
  - no-log-password
  - no-prompting
  - no-same-owner
  - only-builtins
risk:
  - no-free-form
security:  # Rules related o potentially security issues, like exposing credentials
  - no-log-password
syntax:
  - no-free-form
unpredictability:  # Warn about code that might not work in a predictable way
  - avoid-implicit
  - ignore-errors
  - partial-become
  - risky-file-permissions
unskippable:  # Indicate a fatal error that cannot be ignored or disabled
  - load-failure
yaml:  # External linter which will also produce its own rule codes
  - yaml
命令行
检查是否按照最佳实践编写了处理ansible.builtin.shell模块和ansible.builtin.command模块的代码。
- 
- command-instead-of-module
 
- 
- command-instead-of-shell
 
- 
- deprecated-command-syntax
 
- 
- inline-env-var
 
- 
- no-changed-when
 
- risky-shell-pipe
核心
这是用于Ansible lint的内部处理的规则。
- 
- internal-error
 
- 
- load-failure
 
- 
- parser-error
 
- 
- syntax-check
 
- 
- warning
 
- schema
警告
检查Playbook和Role的书写方式是否为过时的格式,以及是否使用了Ansible core或Ansible community中被弃用的模块。
- 
- deprecated-bare-vars
 
- 
- deprecated-command-syntax
 
- 
- deprecated-local-action
 
- 
- deprecated-module
 
- 
- no-jinja-when
 
- role-name
实验性的
这些规则是相对较新的导入规则。如果在这些规则中发现违反,初始设定下将输出警告而非错误提示。
- 
- warning
 
- 
- avoid-implicit
 
- 
- galaxy
 
- 
- ignore-errors
 
- 
- key-order
 
- 
- no-free-form
 
- 
- no-log-password
 
- 
- no-prompting
 
- 
- only-builtins
 
- 
- risky-file-permissions
 
- 
- run-once
 
- 
- schema
 
- var-naming
格式化
检查代码是否符合Ansible Lint所定义的编码规范。
- 
- yaml
 
- 
- fqcn
 
- 
- jinja
 
- 
- key-order
 
- 
- no-tabs
 
- 
- playbook-extension
 
- risky-octal
幂等性
检查是否存在在执行Playbook或Role时无法保证幂等性的描述。
- 
- latest
 
- 
- no-changed-when
 
- package-latest
改变态度说话方法、写作方式或做事的方法。
改变态度在工作、学习或生活中的用处是很大的。
积极改变态度有利于提高工作效率。
改变态度也可以帮助我们更好地与他人沟通。
在困难面前改变态度能够增强我们的应对能力。
只要我们能积极改变态度,就能够战胜困难。
我们将检查是否存在不可预料的操作或副作用的描述。
- 
- command-instead-of-module
 
- 
- command-instead-of-shell
 
- 
- empty-string-compare
 
- 
- inline-env-var
 
- 
- literal-compare
 
- 
- loop-var-prefix
 
- 
- name
 
- 
- no-handler
 
- 
- no-relative-paths
 
- 
- run-once
 
- var-naming
元数据
检查 Galaxy Collection 和角色的元数据文件的描述是否违反规定。
- 
- galaxy
 
- 
- meta-incorrect
 
- 
- meta-no-info
 
- 
- meta-no-tags
 
- 
- meta-video-links
 
- role-name
选择加入
在初始设定中,这是一个被禁用的规则。通过Ansible lint的配置文件中的enable_list进行设置后,它将变为有效。
- 
- empty-string-compare
 
- 
- galaxy
 
- 
- no-log-password
 
- 
- no-prompting
 
- 
- no-same-owner
 
- only-builtins
风险
使用ansible.builtin.command模块或ansible.builtin.raw模块时,检查是否存在可能引发副作用的描述。
- no-free-form
安全
执行Ansible时,将检查密码等秘密信息是否被输出到日志中。有关Ansible日志,请参考“Ansible 出力のロギング — Ansible Documentation”。
- no-log-password
语法
无需说明
- no-free-form
不可预测性
如果描述的操作可能无法按照意图执行,将发出警告。
- 
- avoid-implicit
 
- 
- ignore-errors
 
- 
- partial-become
 
- risky-file-permissions
无法跳过 这个选项 无法略过
当Ansible lint无法检查文件时,会产生该输出。无法检查的主要原因有
- 
- ファイルのエンコーディングエラー(Ansible lintはUTF-8のみ扱える)
 
- 
- Ansibleがサポートする形式のファイルではない
 
- 
- YAMLファイルではない
 
- ファイルにAnsible vaultで解読できない記述が含まれている
可能会考虑等等。
- load-failure
YAML
使用yamllint检查Playbook,角色等是否按照设定的格式进行了描述。
- yaml
 
    