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
.yml
scripts with three dashes (---
). - End all your
.yml
files with a newline (\n
). - Always double quote strings. Don't quote integers or booleans (e.g.
42
ortrue
/false
). - Only use
true
andfalse
for boolean values. - Use one space after the colon in a key/value pair (e.g.
key: value
instead ofkey : value
). - Always use the map syntax for dictionaries.
- When files need to be transferred, use templates.
- All templates should have the
ansible_managed
header and the.j2
file extension. - Use
become
instead ofsudo
. - Blank lines between two blocks and tasks.
snake_case
for 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