summaryrefslogtreecommitdiffstats
path: root/src/ansiblelint/rules/literal_compare.md
diff options
context:
space:
mode:
Diffstat (limited to 'src/ansiblelint/rules/literal_compare.md')
-rw-r--r--src/ansiblelint/rules/literal_compare.md32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/ansiblelint/rules/literal_compare.md b/src/ansiblelint/rules/literal_compare.md
new file mode 100644
index 0000000..5e25394
--- /dev/null
+++ b/src/ansiblelint/rules/literal_compare.md
@@ -0,0 +1,32 @@
+# literal-compare
+
+This rule checks for literal comparison with the `when` clause.
+Literal comparison, like `when: var == True`, is unnecessarily complex.
+Use `when: var` to keep your playbooks simple.
+
+Similarly, a check like `when: var != True` or `when: var == False`
+should be replaced with `when: not var`.
+
+## Problematic Code
+
+```yaml
+---
+- 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.
+```
+
+## Correct Code
+
+```yaml
+---
+- 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.
+```