Runs on individual files or even lines of individual files (good for diffs)
Needs a set of standards rules to be defined
Roles and playbooks must declare standards version (e.g. # Standards: 1.2 in meta/main.yml)
Ansible-lint
ansible-lint comes with a bunch of builtin rules (more with v3.0)
repeatability
idempotency
readability
etc.
Added some internal ansible-lint rules to our repo too.
Ansible-review standards
Based on ansible-lint checks
Or write your own check in python
A check takes a filename and settings
And returns a Result object, which is effectively a list of Errors.
A sample standard rule
become_rather_than_sudo = Standard(dict(
name = "Use become/become_user/become_method " \
"rather than sudo/sudo_user",
check = lintcheck('ANSIBLE0008'),
types = ["playbook", "task"]
version = "0.9"
))
standards = [
become_rather_than_sudo,
...
]
Warnings
For things that aren't yet standards but are worth knowing about (e.g. deprecated behaviour), a standard without a version will never error, only warn.
Ansible-review benefits
Can review specific lines in set of files ansible-review playbook.yml:14-18 otherthing.yml
Can control which checks are important
Can review older code against older versions for minor changes
Running ansible-review
git ls-files | xargs ansible-review
git diff master | ansible-review
As a commit hook (add -q for just errors and warnings)
Results
Conclusions
ansible-review has helped in the review of around 10 internally developed ansible roles so far