Skip to content

Commit

Permalink
Docs: literal compare rule (#2415)
Browse files Browse the repository at this point in the history
* literal compare rule docs

* Update literal_compare.md

Co-authored-by: Sorin Sbarnea <sorin.sbarnea@gmail.com>
  • Loading branch information
oraNod and ssbarnea committed Sep 16, 2022
1 parent 9fd8947 commit 6fc56b2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/ansiblelint/rules/literal_compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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.

## 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.
```

0 comments on commit 6fc56b2

Please sign in to comment.