Using Ansible
In order to use Ansible, we first need to define the inventory, which represents the available resources. Then, we will be able to either execute a single command or define a set of tasks using the Ansible playbook.
Creating an inventory
An inventory is a list of all the servers that are managed by Ansible. Each server requires nothing more than the Python interpreter and the SSH server installed. By default, Ansible assumes that SSH keys are used for authentication; however, it is also possible to use a username and password by adding the --ask-pass
option to the Ansible commands.
Tip
SSH keys can be generated with the ssh-keygen
tool, and they are usually stored in the ~/.ssh
directory.
The inventory is defined by default in the /etc/ansible/hosts
file (but its location can be defined with the –i
parameter), and it has the following structure:
[group_name] <server1_address> <...