Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: literal compare rule #2415

Merged
merged 2 commits into from
Sep 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
```