Table of Contents

Ansible - best practices

Naming things

---
- name: Example playbook
  hosts: localhost
  vars:
    CamelCase: true # <- Contains a mix of lowercase and uppercase characters.
    ALL_CAPS: bar # <- Contains only uppercase characters.
    v@r!able: baz # <- Contains special characters.
    hosts: [] # <- hosts is an Ansible reserved name
    role_name: boo # <-- invalid as being Ansible special magic variable
 
---
- name: Example playbook
  hosts: localhost
  vars:
    lowercase: true # <- Contains only lowercase characters.
    no_caps: bar # <- Does not contains uppercase characters.
    variable: baz # <- Does not contain special characters.
    my_hosts: [] # <- Does not use a reserved names.
    my_role_name: boo

YAML and Jinja2 Syntax

example_list:
  - example_element_1
  - example_element_2
  - example_element_3
  - example_element_4
- name: Call a very long command line
  ansible.builtin.command: >-
    echo Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Maecenas mollis, ante in cursus congue, mauris orci tincidunt nulla,
    non gravida tortor mi non nunc.