Difficulty: Beginner
Estimated Time: 10 minutes

Learn to develop Ansible roles

Ansible roles are great, because you can write once, reuse many times, introduce unit-testing, push complexity into roles, keeping your playbook simple.

We'll learn how Ansible roles work, how you can write and include roles.

Please wait a minute while ansible is being installed using:

pip install ansible
  

pip installs the most recent version of Ansible but won't be updated when running operating system patches.

You could also use the package manager that your distribution provides:

  • Ubuntu: apt-get install ansible
  • Fedora: dnf install ansible
  • CentOS or RHEL: yum install ansible

Developing Ansible roles

Step 1 of 6

Step 1

Create a new role

You've been asked to ensure the times are set correctly on all components.

Some Linux distributions use ntp, other use chrony and who knows what the future will bring.

Our role needs to react differently on all the components. (Fedora, CentOS 7 and Ubuntu)

GO!

Start by using ansible-galaxy to create a new role called timesync.