This is mostly a summary from this styleguide. Don't hesitate to ask any questions if you don't get or disagree with something here. If you're confused about something because it is underspecified, please add an example after you figured it out.
- Start your
.ymlscripts with three dashes (---). - End all your
.ymlfiles with a newline (\n). - Always double quote strings. Don't quote integers or booleans (e.g.
42ortrue/false). - Only use
trueandfalsefor boolean values. - Use one space after the colon in a key/value pair (e.g.
key: valueinstead ofkey : value). - Always use the map syntax for dictionaries.
- When files need to be transferred, use templates.
- All templates should have the
ansible_managedheader and the.j2file extension. - Use
becomeinstead ofsudo. - Blank lines between two blocks and tasks.
snake_casefor variables.- If you define multiple variables with the same prefix, put them in a map.
Good:
- name: "install htop"
package:
name: htop
state: installed
Bad:
- name: "install htop"
package: name=htop state=installed
Good:
koala:
environment: production
server: unicorn
git_ref: ansible_test
ruby_version: 2.3.0
Bad:
koala_environment: production
koala_server: unicorn
koala_git_ref: ansible_test
koala_ruby_version: 2.3.0