Advanced Control over Role Requirements Files
For more advanced control over where to download roles from, including support for remote repositories, Ansible 1.8 and later support a new YAML format for the role requirements file, which must end in a ‘yml’ extension. It works like this:
ansible-galaxy install -r requirements.yml
The extension is important. If the .yml extension is left off, the ansible-galaxy CLI will assume the file is in the “basic” format and will be confused.
And here’s an example showing some specific version downloads from multiple sources. In one of the examples we also override the name of the role and download it as something different:
# from galaxy
- src: yatesr.timezone
# from GitHub
- src: https://github.com/bennojoy/nginx
# from GitHub, overriding the name and specifying a specific tag
- src: https://github.com/bennojoy/nginx
version: master
name: nginx_role
# from a webserver, where the role is packaged in a tar.gz
- src: https://some.webserver.example.com/files/master.tar.gz
name: http-role
# from Bitbucket
- src: git+http://bitbucket.org/willthames/git-ansible-galaxy
version: v1.4
# from Bitbucket, alternative syntax and caveats
- src: http://bitbucket.org/willthames/hg-ansible-galaxy
scm: hg
# from GitLab or other git-based scm
- src: git@gitlab.company.com:mygroup/ansible-base.git
scm: git
version: 0.1.0
As you can see in the above, there are a large amount of controls available to customize where roles can be pulled from, and what to save roles as.
You can also pull down multiple roles from a single source (just make sure that you have a meta/main.yml file at the root level).
meta\main.yml
common-role1\tasks\main.yml
common-role2\tasks\main.yml
For example, if the above common roles are published to a git repo, you can pull them down using:
# multiple roles from the same repo
- src: git@gitlab.company.com:mygroup/ansible-common.git
name: common-roles
scm: git
version: master
You could then use these common roles in your plays
---
- hosts: webservers
roles:
- common-roles/common-role1
- common-roles/common-role2
Roles pulled from galaxy work as with other SCM sourced roles above.
Example:
ansible-galaxy install -r requirements.yml -p /tmp
(requirements.yml contains role specification , version : is the version tag in source control , name: is the role name)