Lab 6 - Roles

Mandatory

Your first role

  • Check out the copy module, you will use it in this lab.

  • Connect to your srv.<firstname>.lab as ansible user

  • Switch into your git repo /home/ansible/training

  • create a roles directory

  • Create a ntp role directory

  • Create a ntp/files directory

  • Copy your /etc/ntp.conf into this directory -> cp /etc/ntp.conf /home/ansible/training/roles/ntp/files/ntp.conf

  • Create a ntp role with the following tasks in the tasks/main.yml.

    • installation via apt module
    • configuration via copy module (src: ntp.conf)
    • notify a handler after a config change

Playbook with a role

  • Create a new playbook named ntp-role.yml
  • Link web1.<firstname>.lab with the new role
  • Run the playbook

Add Tags to the ntp role

  • Tag the configuration task with configuration
  • Tag the installation task with installation

Test the handler

  • change the ntp config files/ntp.conf
  • Run the playbook again -> service should be restarted

Create a python-pip role

  • Create a new python-pip role
  • use the package module for the installation of the package python-pip
  • extend the role list with the python-pip role in the already existing ntp-role.yml playbook

Run playbook with tag

Run only the tag installation

Commit your changes

  • add all files to your git repo and commit it