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.cfg`` in the ``[defaults]`` section with ``roles_path`` * Install the galaxy role ``pstauffer.epel`` * Check out the installed role ``roles/pstauffer.epel`` .. code-block:: bash # 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.yml`` to run the ``EPEL`` role on your ``web2..lab`` server * Run the playbook .. code-block:: yaml # 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-pip`` role * The role should install the ``python-pip`` package .. code-block:: yaml 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 ``meta`` directory in the ``python-pip`` role * create a role dependency on the installed ``pstauffer.epel`` role in ``meta/main.yml`` * the dependency should only run on the ``ansible_os_family`` **RedHat** * Create a playbook ``pip.yml`` to run the role ``python-pip`` on the ``web`` hostgroup * Run the playbook .. hint:: ``pstauffer.epel`` should only run on RedHat. -> Use ``when:`` and ``ansible_os_family`` in the dependencies. .. code-block:: yaml 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 .. code-block:: bash ansible-playbook pip.yml Commit your changes ------------------- * add all files to your git repo and commit it .. code-block:: bash git status git add roles/* git commit -m 'lab 9'