ansibleansible-collections

How do I install a built Ansible collection (tar.gz) directly from a http url without a Galaxy server or using Ansible Galaxy?


The Ansible collections documentation provides a number of ways for installing collections. The primary focus is on installing from Ansible Galaxy.

However, I would like to host and install built collections (tar.gz) from an internal web server.

At this point, I am not interested in self-hosting a Galaxy server or installing the collections from a git repo (I don't want to have to deal with permissions).

Is there a way to specify a url as the collection source when using ansible-galaxy collection install.

That is, can this work?

 $ ansible-galaxy collection install http://example.com/collection-X.X.X.tar.gz

and would I be able to specify a url path in requirements.yml?


Solution

  • This can be done directly on the command line and in the requirements file.

    1. Directly on the command line

    ansible-galaxy supports installing a collection from a build (tar.gz) using

      $ ansible-galaxy install  <collection.tar.gz>
    

    If the collection is hosted on a web server the source can be passed to the command

      $ ansible-galaxy install  http://example.com/collection-X.X.X.tar.gz
      Downloading http://example.com/collection-X.X.X.tar.gz to <tmp directory>
    Starting galaxy collection install process
    Process install dependency map
    Starting collection install process
    Installing 'collection:X.X.X' to '<collection folder>'
    
    1. Using a requirements file

    Ansible collections can be installed using a requirements file.

    The documentation lists url as a supported value for the type key for collection entries.

    Therefore to install the collection hosted at http://example.com/collection-X.X.X.tar.gz add the following entry to the collections key of the requirements file

    ---
    
    # requirements.yml
    
    collections: # Note: all collections must be listed under this key
    
      - name: <namespace.collection>
        type: url
        source: http://example.com/collection-X.X.X.tar.gz
    
    

    and install using

      $ ansible-galaxy collection install -r requirements.yml
    Starting galaxy collection install process
    Process install dependency map
    Downloading http://example.com/collection-X.X.X.tar.gz to <tmp directory>
    Starting collection install process
    Installing 'namespace.collection:X.X.X' to '<collections directory>'
    namespace.collection:X.X.X was installed successfully
    
    

    The version key can be specified but the value provided must match the version in the name of the archive.

    ---
    
    # requirements.yml
    
    collections: # Note: collections must be listed under this key
    
      - name: <namespace.collection>
        type: url
        version: X.Y.Z # this will fail. value must be X.X.X
        source: http://example.com/collection-X.X.X.tar.gz