Ansible-lint: Difference between revisions

From DWIKI
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
=FAQ=
=FAQ=
==Don't compare to empty string==
* Use `when: var | length > 0` instead of `when: var != ""`.
* Use `when: var | length == 0` instead of `when: var == ""`.


==Don't compare to literal True/False==
==Don't compare to literal True/False==
Line 17: Line 20:


==Shells that use pipes should set the pipefail option==
==Shells that use pipes should set the pipefail option==
  shell: set -o pipefail && ...
  shell: |
  set -o pipefail
  your command
  args:
  executable: /bin/bash

Latest revision as of 11:46, 27 September 2024

FAQ

Don't compare to empty string

  • Use `when: var | length > 0` instead of `when: var != ""`.
  • Use `when: var | length == 0` instead of `when: var == ""`.

Don't compare to literal True/False

Instead of

when: (foo == 1 and bar == 0) == false

use

when: not (foo == 1 and bar == 0) 

Commands should not change things if nothing needs doing

Sometimes fixed by adding

changed_when: false


Lines should be no longer than 160 chars

ignore for now?


Shells that use pipes should set the pipefail option

shell: |
  set -o pipefail
  your command
args:
  executable: /bin/bash