View on GitHub

ansible.training.crafteo.io

Ansible training pages for Crafteo - crafteo.io

Use roles with Ansible Galaxy

Ansible Galaxy provides roles maintained by the Ansible community and open-sourced. They can easily be installed and used in playbooks.

Install role globally

Let’s use an Apache role from Ansible Galaxy to install and configure our Apache server:

Run your playbook and check everything is working. You should see a few more tasks being run - do not hesitate to visit the role’s source code to see how it’s done!

Override role’s default configuration

geerlingguy role’s configure Apache server to listen on port 80 by default. We want to listen on port 8080 instead:

Run your playbook and check everything is working. Your Apache server should be available on port 8080

Install role using requirements.yml

Create a requirements.yml file to define the role(s) and version we want to use. Install the roles using ansible-galaxy commands.

This setup is typically used on CI when testing our role to install all its dependencies. It’s much like a Python requirements.txt.

Use Galaxy role alongside our own role

We now have a role to manage our Apache installation, but what about our static website content?

Update our previous apache role:

Run your playbook and check everything is working.