跳至内容

literal-compare

此规则检查`when`子句中的字面比较。字面比较,例如`when: var == True`,是不必要的复杂。使用`when: var`使您的playbook更简洁。

类似地,像`when: var != True`或`when: var == False`这样的检查应该替换为`when: not var`。

问题代码

---
- name: Example playbook
  hosts: all
  tasks:
    - name: Print environment variable to stdout
      ansible.builtin.command: echo $MY_ENV_VAR
      when: ansible_os_family == True # <- Adds complexity to your playbook.

正确代码

---
- name: Example playbook
  hosts: all
  tasks:
    - name: Print environment variable to stdout
      ansible.builtin.command: echo $MY_ENV_VAR
      when: ansible_os_family # <- Keeps your playbook simple.