5

When downloading roles it's possible to specify roles. One of several ways would be with the following requirements.yml file:

---
- src: https://github.com/jdauphant/ansible-role-ssl-certs
  version: v1.5.2

This role could then be downloaded with the following command:

ansible-galaxy install -r requirements.yml

How do you then specify which version of a role to use in an Ansible playbook?

  roles:
    - jdauphant.ssl-certs
techraf
  • 64,883
  • 27
  • 193
  • 198
Leonard Saers
  • 649
  • 9
  • 28

1 Answers1

5

There is no option to save different versions of a playbook under the same name and then to specify which version to run in a playbook.

You can:

  • "bind" a particular role version to the playbook by downloading out to the roles subdirectory of the project directory (the one containing the playbook). Ansible will then use this version before trying roles faced in the system roles directory.

    Add path to the requirements.yml:

    - src: https://github.com/jdauphant/ansible-role-ssl-certs
      version: v1.5.2
      path: roles/
    
  • save different versions under different names (i.e. in different directories) system-wide:

    - src: https://github.com/jdauphant/ansible-role-ssl-certs
      version: v1.5.2
      name: jdauphant.ssl-certs-1.5.2
    

    And reference a particular name:

    roles:
       - jdauphant.ssl-certs-1.5.2
    
techraf
  • 64,883
  • 27
  • 193
  • 198
  • Thanks for the answerer. I like your suggested approach, but It's a bit strange that a work around is needed in ansibel for specifying version. – Leonard Saers Aug 21 '16 at 18:49
  • Ansible Galaxy at this moment does not even have a option to upgrade a role. You need to delete a role and install it again. Besides Ansible being work in progress, I don't think it makes much sense to implement such feature. It would just create a versioning mess that Ansible was supposed to deal with. – techraf Aug 22 '16 at 00:30