Introduction
Users must provide two files to Ansible: a inventory listing the managed nodes and a playbook listing the operations to be performed on the managed nodes.
Inventory
The inventory is a YAML in the format
managed_node.com:
hosts:
one.managed_node.com:
two.managed_node.com:
where:
managed_node.comis the name of the group.hostsis a reserved workd.one.managed_node.comandtwo.managed_node.comare the name of the servers.
Variables
The inventory can contain variables and some variables are used to controls how Ansible interacts with the managed node. For example,
ansible_hostconfigures the IP used when connecting to the managed node.ansible_userconfigures the user name used when connecting to the managed node.ansible_passwordconfigures the password used when connecting to the managed node.
Warning
The password must not be stored as plain text in the inventory. It is recommended to use vault to store passwords as illustrated in Hello World with Vault.
The inventory would be
managed_node.com:
hosts:
one.managed_node.com:
ansible_user: alice
ansible_password: 123alice456
two.managed_node.com:
ansible_user: bob
ansible_password: 123bob456
Tip
Variables can also be defined for the group.
managed_node.com:
hosts:
one.managed_node.com:
two.managed_node.com:
vars:
ansible_user: alice
ansible_password: 123alice456
The full list of this variables is in Connecting to hosts: behavioral inventory parameters.
Playbook
The playbook is a YAML with a list of plays, for example
- name: Configure servers
hosts:
- managed_node.com
tasks:
...
- name: Start servers
hosts:
- managed_node.com
tasks:
...
Tip
It is recommended to use ansible-lint to check the playbook for errors.
To run a playbook, use
ansible-playbook \
--inventory path/to/production.yml \
playbook.yml