Ansible Roles promotes code reusability and provides a simple method for packaging Ansible code in a simple way that can be shared and consumed. An Ansible role is a collection of all the required Ansible tasks, handlers, and Jinja2 templates that are packaged together in a specific structure. A role should be designed in order to deliver a specific function/task. In this recipe, we will outline how to create an Ansible role and how to use it in our playbooks.
- Inside the ch1_ansible folder, create a new folder called roles and create a new role called basic_config, as shown here:
$ mkdir roles
$ cd roles
$ ansible-galaxy init basic_config
- Update the basic_config/vars/main.yml file with...