-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* literal compare rule docs * Update literal_compare.md Co-authored-by: Sorin Sbarnea <sorin.sbarnea@gmail.com>
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
``` |