Search code examples
ansibleansible-galaxy

ansible-galaxy - specify version range to install


I am trying to install an Ansible Galaxy collection, but I need to force an older revision. According to the documentation, I tried to perform installation the following ways:

$ ansible-galaxy collection install 'weareinteractive.ufw:>=1.10.0,<2.0.0'
Process install dependency map
ERROR! Failed to find collection weareinteractive.ufw:>=1.10.0,<2.0.0
$ ansible-galaxy collection install 'weareinteractive.ufw:<2.0.0'
Process install dependency map
ERROR! Failed to find collection weareinteractive.ufw:<2.0.0

I globally get the same kind of error when trying to do the same from this requirements.yml:

---
- name: weareinteractive.ufw
  version: '>=1.8.0,<2.0.0'

Running the command

$ ansible-galaxy install -r requirements.yml
- downloading role 'ufw', owned by weareinteractive
[WARNING]: - weareinteractive.ufw was NOT installed successfully: - the specified version (>=1.8.0,<2.0.0) of weareinteractive.ufw was not found in the list of available versions ([{'id': 141713, 'url': '', 'related': {}, 'summary_fields': {}, 'created':
'2020-11-25T18:52:30.171540Z', 'modified': '2020-11-25T18:52:30.171568Z', 'name': '2.0.1', 'version': '2.0.1', 'commit_date': '2020-11-25T10:51:53-05:00', 'commit_sha': '30b1fdc8f5440e865d3fbeb83894941bf70739c7', 'download_url':
'https://github.com/weareinteractive/ansible-ufw/archive/2.0.1.tar.gz', 'active': None}, {'id': 76043, 'url': '', 'related': {}, 'summary_fields': {}, 'created': '2018-10-04T14:07:47.602784Z', 'modified': '2018-10-04T14:07:47.602810Z', 'name': '1.8.0', 'version':
'1.8.0', 'commit_date': '2018-10-04T10:05:07-04:00', 'commit_sha': 'ae776a7dc255ba5dc679cedee32129ba22c0e797', 'download_url': 'https://github.com/weareinteractive/ansible-ufw/archive/1.8.0.tar.gz', 'active': None}, .....]).
ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.

What am I missing?

Edit: I'm using ansible / ansible-galaxy 2.9.16 but I expect a solution that will still works with ansible 2.10


Solution

  • As stated in the front page of the repository of the role you are trying to install:

    Ansible weareinteractive.ufw role

    Source: https://github.com/weareinteractive/ansible-ufw#ansible-weareinteractiveufw-role

    It is a role and not a collection.

    Although the two syntaxes might lookalike, they actually don't totally have the same syntax.
    For a role, first, you don't install them via

    ansible-galaxy collection install some-collection
    

    Obviously, but via:

    ansible-galaxy install some-role
    

    Note: this is confirmed by both their GitHub page and their Ansible Galaxy page, that advise you to install the role via

    ansible-galaxy install weareinteractive.ufw
    

    Sources: https://galaxy.ansible.com/weareinteractive/ufw and https://github.com/weareinteractive/ansible-ufw


    Then, the version pinning differs too. On a role you have to specify a version, not a version range:

    When the Galaxy server imports a role, it imports any git tags matching the Semantic Version format as versions. In turn, you can download a specific version of a role by specifying one of the imported tags.

    Source: https://docs.ansible.com/ansible/latest/galaxy/user_guide.html#installing-a-specific-version-of-a-role

    So you'll have to base yourself on the git tags of their repo, e.g.

    ansible-galaxy install weareinteractive.ufw,v1.10.0
    

    And the requirement.yml also differs a bit, where you also have to give a specific verison.

    - name: weareinteractive.ufw
      version: v1.10.0