Ansible 101 : A Short introduction to automation, Playbooks, ...
Ansible is an automation tool, but there are other tools like Puppet and Chef for example.
Ansible files are human readable and it uses SSH to communicate between machines.
It is also agentless, so there is no need to install extra software on the target machines.
To use Ansible, we would need to install python, its dependencies and OpenSSH for secure communication between the machines.
We can check if Ansible is installed on our machine using the below command:
With all these elements in place - python, ssh, ... -, we could run Ansible.
We could use the command line to run the below Ansible command that uses the "shell" module with the "find" command:
Below is a short explanation of the arguments used in the above command:
- all : the command is executed on all the hosts of the inventory.
- -a : the module's arguments.
- -m : module/action to run, the default module "type" is a command
- -i : stands for "inventory", in our example we have just specified a couple of hosts separated by a coma.
If we need to run more than one simple command, then we would need to use playbooks.
Playbooks allow us to run scripts instead of running individual
commands like we did earlier.
To run our playbook we run the below command:
Below is a short explanation of some of the parameters in the Yaml file:
- --- : tells us that this is a Yaml file.
- hosts : represents the hosts that we are running the tasks on.
- -name : gives us a description of the task
- debug/ping : represent a couple of modules to be run on the hosts of the inventory.