Lab 9 - Solution¶
Mandatory¶
Installation of a ansible-galaxy role¶
- Have a look at https://galaxy.ansible.com/pstauffer/epel
- Define your roles directory in the
ansible.cfgin the[defaults]section withroles_path - Install the galaxy role
pstauffer.epel - Check out the installed role
roles/pstauffer.epel
# define the roles_path
vi ansible.cfg
# file: ansible.cfg
roles_path = roles
# install the role
ansible-galaxy install pstauffer.epel
# verify the installation
ansible-galaxy list
- pstauffer.epel, master
# have a look at the new role
cat roles/pstauffer.epel/tasks/main.yml
cat roles/pstauffer.epel/defaults/main.yml
- Create a simple playbook
epel.ymlto run theEPELrole on yourweb2.<firstname>.labserver - Run the playbook
# file: epel.yml
---
- hosts: web2.pascal.lab
roles:
- pstauffer.epel
# run playbook
ansible-playbook epel.yml
Python-Pip Role for Debian and RedHat¶
- Create / Edit the
python-piprole - The role should install the
python-pippackage
mkdir -p roles/python-pip/tasks
# file: roles/python-pip/tasks/main.yml
---
- name: install python-pip
package:
name: python-pip
state: present
- on RedHat is EPEL needed to install
python-pip - create the
metadirectory in thepython-piprole - create a role dependency on the installed
pstauffer.epelrole inmeta/main.yml - the dependency should only run on the
ansible_os_familyRedHat - Create a playbook
pip.ymlto run the rolepython-pipon thewebhostgroup - Run the playbook
Hint
pstauffer.epel should only run on RedHat.
-> Use when: and ansible_os_family in the dependencies.
mkdir roles/python-pip/meta
# file: roles/python-pip/meta/main.yml
---
dependencies:
- role: pstauffer.epel
when: ansible_os_family == "RedHat"
# playbook file: pip.yml
---
- hosts: web
roles:
- python-pip
ansible-playbook pip.yml
Commit your changes¶
- add all files to your git repo and commit it
git status
git add roles/*
git commit -m 'lab 9'