Reputation:
The documentation for ansible-galaxy
indicates the following:
The ansible-galaxy command comes bundled with Ansible, and you can use it to install roles from Galaxy or directly from a git based SCM. You can also use it to create a new role, remove roles, or perform tasks on the Galaxy website.
I'm trying to figure out how it's possible to install an Ansible collection "directly from a git based SCM" as indicated. When I run ansible-galaxy collections --help
, from Ansible 2.9.1 on MacOS Catalina, I see the following:
usage: ansible-galaxy collection install [-h] [-s API_SERVER]
[--api-key API_KEY] [-c] [-v] [-f]
[-i] [-n | --force-with-deps]
[-p COLLECTIONS_PATH]
[-r REQUIREMENTS]
[collection_name [collection_name ...]]
positional arguments:
collection_name The collection(s) name or path/url to a tar.gz
collection artifact. This is mutually exclusive with
--requirements-file.
optional arguments:
-h, --help show this help message and exit
-s API_SERVER, --server API_SERVER
The Galaxy API server URL
--api-key API_KEY The Ansible Galaxy API key which can be found at
https://galaxy.ansible.com/me/preferences. You can
also use ansible-galaxy login to retrieve this key or
set the token for the GALAXY_SERVER_LIST entry.
-c, --ignore-certs Ignore SSL certificate validation errors.
-v, --verbose verbose mode (-vvv for more, -vvvv to enable
connection debugging)
-f, --force Force overwriting an existing role or collection
-i, --ignore-errors Ignore errors during installation and continue with
the next specified collection. This will not ignore
dependency conflict errors.
-n, --no-deps Don't download collections listed as dependencies.
--force-with-deps Force overwriting an existing collection and its
dependencies.
-p COLLECTIONS_PATH, --collections-path COLLECTIONS_PATH
The path to the directory containing your collections.
-r REQUIREMENTS, --requirements-file REQUIREMENTS
A file containing a list of collections to be
installed.
I tried specifying a GitHub repository URI for the -p
parameter, but instead of recognizing a valid URI, ansible-galaxy
tried to look in a subfolder named the URI that I specified.
ansible-galaxy collection install -p https://github.com/pcgeek86/ansible-galaxy-test trevor.trevormacos
My expectation would be that specifying a GitHub repository URI for the -p
parameter should properly indicate that I want to install a collection from that GitHub repository.
Question: How do I instruct ansible-galaxy
to install an Ansible collection directly from a GitHub URI?
Upvotes: 16
Views: 16475
Reputation: 166389
Here is a command-line syntax to install role from git repo (e.g. GitHub):
ansible-galaxy install git+https://github.com/myorg/ansible-role-example.git
To specify branch, append ,mybranch
at the end of the command.
Upvotes: 4
Reputation: 386
Since recent Ansible version 2.10 this is now possible.
See: https://github.com/ansible/ansible/pull/69154
To use it you specify similar to roles:
collections:
- name: [email protected]:my_org/private_collections.git#/path/to/collection,devel
- name: https://github.com/ansible-collections/amazon.aws.git
type: git
version: 8102847014fd6e7a3233df9ea998ef4677b99248
Upvotes: 10