Roles can also include handler tasks, which are tasks that will be performed upon successful completion of all the tasks in tasks/main.yml in the playbook. Ansible will look for roles in a roles directory set in the Ansible.cfg file or in the same directory in which the playbook is stored. One or more roles can be run as part of the playbook. All the functionality available in the role is available with a single include_role statement in the playbook. Once the role is complete, you can include it in a playbook, as shown in Figure 47. Default values can also be set in the defaults/main.yml file. Any variables that the playbook uses should be called out in the README.md file with examples. If you are using anchors and hooks to group variables, you must add a set_fact statement, as shown in Figure 46. The tasks keyword is not needed because the role structure has defined that this file will contain tasks. Unlike a playbook, the tasks/main.yml file is simply a list of tasks. yml file is similar to a playbook: Tasks are run in order. Initializing a new Ansible role with the ansible-galaxy commandĪt a minimum, the role should have the main.yml file filled out in the tasks directory. Figure 45 shows the creation of a new role and the default directories created.įigure 45. You can omit any directories the role does not use. You must include at least one of these directories in each role. That structure can then be fleshed out with content.Īn Ansible role has a defined directory structure with up to eight main standard directories. This command creates a default directory structure for your role. Roles are created with the Ansible-galaxy init role-name command. Ansible documentation about roles provides more detail.Ī role in Ansible is basically a well-defined playbook that is designed to be shared and reused. This section gives a brief summary of how to create and use roles. One way to do this is by using Ansible roles. Ansible provides several different ways to organize your tasks to make them reusable and easy to maintain. Previous sections have looked at playbooks as a list of tasks that run a single long playbook.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |