Ansible Galaxy - Managing Role Dependencies Using Git Repositories
Ansible Galaxy - Managing Role Dependencies Using Git Repositories
February 16, 2017
Uploading Ansible Role to Git Repository
First, create a Git repository for developing an Ansible Role. Then, generate the initial Ansible Role project structure using Ansible Galaxy.
- Clone the Git repository to your local machine.
| |
- Generate Ansible Role initial directory and files.
| |
- After developing the Ansible Role, push to Git repository.
| |
Downloading Ansible Role from Git Repository
Method 1) Download via Ansible Galaxy CLI
| |
Method 2) Specify in dependency file and download via CLI
| |
Writing ‘requirements.yml’
- src
- username.role_name: Used to download Ansible Roles registered in the official Ansible Galaxy repository.
- url: Used to download from SCMs supported by Ansible Galaxy.
- scm
- Specify the SCM name to integrate. Default is ‘git’ (as of ansible-galaxy 2.2.1.0, only git and hg are supported)
- version
- Specify tag name / commit hash / branch name. Default is ‘master’
- Only used when downloading from SCM.
- name
- Specify the name of the downloaded Ansible Role. By default, uses the name registered in Ansible Galaxy or the Git repository name.
See the examples below:
| |
PS. When pulling a role from a private repository such as an internal GitLab, the SSH form git@... from the last example was the easiest. ansible-galaxy calls git clone internally, so if ssh -T git@gitlab.company.com works on that machine, it just works with no extra setup. Putting a token in an HTTPS URL also works, but requirements.yml gets committed to the repository too, so I don’t recommend it.
Also, if version is a branch name you can get different code on every install, so pinning a tag or commit hash is safer for production.