View on GitHub

ansible.training.crafteo.io

Ansible training pages for Crafteo - crafteo.io

Ansible: example playbook

Let’s install Ansible and run a simple command on our targets.

Install Ansible

Install Ansible by running commands:

sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible

Check Ansible installed with:

ansible --version

Full installation instructions can be found on Ansible installation doc


Our first Ansible playbook

Let’s run our first Ansible playbook. Clone this repository:

git clone https://github.com/PierreBeucher/workshop-ansible-playbook.git

Before running the playbook, we need to tell Ansible on which nodes it must connect to and take actions. This is done via the Ansible hosts file. We’ll use the hosts file in inventory inventories/dev/hosts.

Note: an inventory is a component allowing Ansible to configure hosts, we’ll come back to that later.

This ran all the tasks defined in playbook.yml on nodes defined in our hosts file:

Explore the content of playbook.yml to understand what happened.


Bonus exercise: our repository used a login/password in host file to connect to our nodes. Update the inventory to use a local SSH key instead.