Ansible Galaxy

Is a role repository to get and distribute ansible roles.

To use galaxy, you should push your code to github and link each github role repo to your galaxy account.

Demo

Show a demo with a real galaxy account.

Roles are scoped with github username.

Installing roles

Just run the following command to install a very simple role.

Though simple, there are still some files.


In [ ]:
!ansible-galaxy install ioggstream.debug

The role have been downloaded to roles_path or ANSIBLE_ROLES_PATH.

You can inspect it


In [ ]:
!tree /root/.ansible/roles/ioggstream.debug
!cat /root/.ansible/roles/ioggstream.debug/tasks/main.yml

To apply this role to our hosts, use this playbook

- hosts: web
  roles:
  - role: ioggstream.debug

Exercise

Apply this role to our web hosts.

to install multiple roles, write down a requirements.yml (don't confuse it with python's requirements.txt)

requirements.yml can retrieve roles from galaxy, http or git repositories from the doc

# from galaxy
- src: yatesr.timezone

# from GitHub
- src: https://github.com/bennojoy/nginx

# 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 GitLab or other git-based scm
- src: git@gitlab.company.com:mygroup/ansible-base.git
  scm: git
  version: "0.1"  # quoted, so YAML doesn't parse this as a floating-point value
`

In [ ]: