View on GitHub

ansible.training.crafteo.io

Ansible training pages for Crafteo - crafteo.io

Ansible roles - building a small Apache role

Lets’ use an Ansible role to deploy Apache with a single static page on multiple environments: Dev and Prod.

For these exercises, checkout the role branch from our repository:

# stash our current changes
# changes may be retrieve using git stash pop
git stash

# checkout role branch
git checkout role 

This branch has a very simple playbook referencing the apache role. The role can be found under roles/apache and define tasks to install Apache with a simple index.html template with a few variables.

Explore role structure

Explore the files unders roles/apache and:

Try to run the playbook with our defined role.

Define multiple inventories and configuration

We now want to define multiple environments, each Ansible inventory representing a different environment:

Using Ansible inventories:

Run your playbook and check changes were applied. Reminder: use -i INVENTORY to specify inventory to use, for example:

# use dev inventory
ansible-playbook -i inventories/dev playbook.yml