See Configuring the ansible-galaxy client if you are using another Galaxy server, such as Red Hat Automation Hub. You can also add the role to the playbook using the include_role module. I will discuss the differences between these two modules in a separate article. If you can`t wait, check the documentation. The following is an example of using –roles-path to install the role in the current working directory: From there, you can import the specified roles or include them in your tasks. For this example, create a playbook in the same directory where you created the roles directory. To do this, run: Run the playbook with the ansible-playbook command with the -K parameter and enter your sudo password to allow Ansible to install the system packages. For this role, add all required tasks to the tasks/main.yml file: If you use the -p option to specify the installation path, use one of the values configured in COLLECTIONS_PATHS, because Ansible itself expects collections here. If you do not specify a path, ansible-galaxy collection install installs the collection in the first path defined in COLLECTIONS_PATHS, which is ~/.ansible/collections by default. Override the default behavior by setting the ANSIBLE_ROLES_PATH environment variable. When this option is set, the ANSIBLE_ROLES_PATH variable is used while the playbook is running to find installed roles, and ansible-galaxy to determine where roles should be installed.

It can be set to a single directory path or to a list of paths (for example, /etc/ansible/roles:~/.ansible/roles). When a list is defined, ansible-galaxy installs the roles in the first writable path. When the Galaxy server imports a role, it imports all Git tags conforming to the Semantic Version format as versions. In turn, you can download a specific version of a role by specifying one of the imported tags. Version of the role to download. Specify a release tag value, validation hash, or branch name. By default, the branch is set by default in the repository; otherwise, the master is set by default. If the source of a role is Galaxy, specify the role in namespace.role_name format: requirements.yml is a list of playbook requests with an optional name and version. ansible-galaxy can search for dependencies on other Galaxy instances configured to support the use case where a collection may depend on a collection of another Galaxy instance. In the article How to use Ansible to set up Vim, I developed an Ansible playbook to set up an initial Vim environment with some Vim plugins. In this recent article, I`ll build on the previous example by converting the playbook to an Ansible role.

Typically, ansible-galaxy has the following structure: Ansible can also install a collection collected with ansible-galaxy collection build or downloaded from Galaxy for offline use by directly specifying the output file: You can optionally set the API token for each server name. Go to and click View API Key. To install a specific version of a role from Galaxy, add a comma and the value of a GitHub version tag. For example, dependencies are listed in a role`s meta/main.yml file with the top-level dependencies keyword. The following is an example of a meta/main.yml file with dependent roles: You now have a role that Vim installs and configures and that you can reuse and share. In the next article in this series, I will enhance this role by adding a template file to make the configuration even more flexible. An Ansible coil is a set of reusable Ansible artifacts. It solves a problem and contains all the relevant tasks, variables, defaults, handlers, modules or other plugins.

For users, the Ansible role is easy to download and share through Ansible Galaxy. For developers, the Ansible role is easy to download and share through Ansible Galaxy. In addition, an Ansible role has a default directory structure and format. You can create the meta/requirements.yml file and define dependencies in the same format that is used for requirements.yml described in Installing multiple roles from a single file. Before you can use a role, you must install it. There are several ways to do this: You can configure a requirements.yml file to install multiple collections in a single command. This file is a YAML file in the following format: If the source of a role is Galaxy, specify the role in namespace.role_name format, as shown in the example above. The more complex format used in requirements.yml is also supported, as shown by the following: Ansible Galaxy refers to the Galaxy website, a free website for finding, downloading, and sharing community-developed roles.