When installing a new role locally from galaxy.ansible.com will put it into a default location in ~/.ansible-galaxy/roles. While it's not necessarily a problem, it's not too intuitive to have them in a hidden directory, especially if all other project files are stored somewhere else on the disk or in a remote location.

One way to deal with it is to permanently configure Ansible to use a specific location for all roles by adding this to ~/.ansible.cfg:

[defaults]
roles_path=~/ansible/roles #change it to your own liking

A more flexible way to have Ansible download a galaxy role is to use a --roles-path= option on the CLI:

ansible-galaxy install user.rolename --roles-path=~/ansible-galaxy

The above role will be downloaded into ~/ansible-galaxy location nice and clean.

More info about roles_path from ansible-config documentation:

DEFAULT_ROLES_PATH:
  default: ~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
  description: Colon separated paths in which Ansible will search for Roles.
  env:
  - {name: ANSIBLE_ROLES_PATH}
  expand_relative_paths: true
  ini:
  - {key: roles_path, section: defaults}
  name: Roles path
  type: pathspec
  yaml: {key: defaults.roles_path}

Published

Category

Ansible

Tags

Contact