Checking shared roles into a single location makes them easier to use in multiple playbooks. If you store your roles in a different location, set the roles_path configuration option so Ansible can find your roles. In the directory where the playbook file is located The default search path is ~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles. In a directory called roles/, relative to the playbook file Storing and finding roles īy default, Ansible looks for roles in the following locations: For more information, please refer to Embedding modules and plugins in roles below. Roles may also include modules and other plugin types in a directory called library. # roles/example/tasks/main.yml - name : Install the correct web server for RHEL import_tasks : redhat.yml when : ansible_facts|lower = 'redhat' - name : Install the correct web server for Debian import_tasks : debian.yml when : ansible_facts|lower = 'debian' # roles/example/tasks/redhat.yml - name : Install web server : name : "httpd" state : present # roles/example/tasks/debian.yml - name : Install web server : name : "apache2" state : present For example, you can place platform-specific tasks in separate files and refer to them in the tasks/main.yml file: You can add other YAML files in some directories. Meta/main.yml - metadata for the role, including role dependencies and optional Galaxy metadata such as platforms supported. Templates/main.yml - templates that the role deploys. Vars/main.yml - other variables for the role (see Using Variables for more information).įiles/main.yml - files that the role deploys. These variables have the lowest priority of any variables available, and can be easily overridden by any other variable, including inventory variables. Library/my_module.py - modules, which may be used within this role (see Embedding modules and plugins in roles for more information).ĭefaults/main.yml - default variables for the role (see Using Variables for more information). Handlers/main.yml - handlers, which may be used within or outside this role. Tasks/main.yml - the main list of tasks that the role executes. j2 files/ # bar.txt # <- files for use with the copy resource foo.sh # <- script files for use with the script resource vars/ # main.yml # <- variables associated with this role defaults/ # main.yml # <- default lower priority variables for this role meta/ # main.yml # <- role dependencies library/ # roles can also include custom modules module_utils/ # roles can also include custom module_utils lookup_plugins/ # or other types of plugins, like lookup in this case webtier/ # same kind of structure as "common" was above, done for the webtier role monitoring/ # "" fooapp/ # ""īy default Ansible will look in each directory within a role for a main.yml file for relevant content (also main.yaml and main): Roles/ common/ # this hierarchy represents a "role" tasks/ # main.yml # <- tasks file can include smaller files if warranted handlers/ # main.yml # <- handlers file templates/ # <- files for use with the template resource 2 # <- templates end in. Controlling how Ansible behaves: precedence rules.Virtualization and Containerization Guides.Protecting sensitive data with Ansible vault.Playbook Example: Continuous Delivery and Rolling Upgrades.Discovering variables: facts and magic variables.Running a role multiple times in one play.Working with language-specific version managers.Controlling where tasks run: delegation and local actions.
0 Comments
Leave a Reply. |