Ansible collections and roles
Install collections and roles, publish and sign collections with ansible-galaxy, read their documentation, and set up the repositories they use.
On this page
Configure ansible-galaxy
The repository's address is the server URL, <base URL>/api/ansible/<project>/<repository>/ with its trailing slash. Set up client renders, for ansible-core 2.17 to 2.21:
# ansible.cfg, next to your playbooks or as ~/.ansible.cfg (example)
[galaxy]
server_list = quader
[galaxy_server.quader]
url=https://quader.example.com/api/ansible/web/ansible/
export ANSIBLE_GALAXY_SERVER_QUADER_TOKEN="${QUADER_TOKEN}" # not for a public repository
touch ~/.netrc && chmod 600 ~/.netrc # roles only
printf 'machine %s login quader password %s\n' quader.example.com "${QUADER_TOKEN}" >>~/.netrc
ansible.cfg expands no variable, so the token stays in the environment: the variable is named after the server (ANSIBLE_GALAXY_SERVER_<NAME>_TOKEN). A role archive is downloaded without the token header, so roles need the ~/.netrc line; without it the lookup works and the download fails with 401. One line serves every repository on the host. A wrong token answers 401, never anonymous content. With several servers, ansible-galaxy takes the first in server_list that has the collection: give it one virtual repository.
| Class | Collections | Roles |
|---|---|---|
| Local | what you publish | none: the client reports that the v1 API is not available |
| Remote | a cache of a Galaxy, the public one by default | translated from the Galaxy's role API; archives from the hosts the remote allows |
| Virtual | the union of its members | from the first remote member that knows the role |
Install and publish
ansible-galaxy collection install acme.tools:1.2.0 # or -r requirements.yml
ansible-galaxy role install geerlingguy.pip
ansible-galaxy collection build # writes acme-tools-1.0.0.tar.gz
ansible-galaxy collection publish acme-tools-1.0.0.tar.gz --server quader
A collection's dependencies resolve through the same servers and rules. A role with a Git or URL source never passes through Quader. --clear-response-cache makes the client forget a removed version.
Publishing needs deploy; on a virtual repository it goes to the deployment target. Namespace, name and version come from galaxy.yml, in lower case. The command prints the server's import messages, warnings included, such as a missing changelog; Quader runs no ansible-lint and no code of the collection.
- The same file again succeeds unchanged; other bytes under a version answer
version_exists. - A deleted version's number is blocked (
version_tombstoned) until an administrator clears its tombstone. - A first publish of a name a remote member already serves needs manage on the repository.
Without a client, Upload collection in the toolbar of a local or virtual repository's page, or on a namespace's page, takes the built archive, runs the same checks and shows the import log.
Publish a role: put it into a collection
Quader takes no role of its own (role import asks a Galaxy to fetch from GitHub). Put the role into the roles/ directory of a collection and publish that:
ansible-galaxy collection init acme.platform
cp -r ./my-role acme/platform/roles/agent
ansible-galaxy collection build acme/platform
A playbook then uses acme.platform.agent, and the collection's documentation lists it under Roles.
Roles from a Galaxy
A remote lists each role a client installed through it, geerlingguy.pip, with the Galaxy's description, tags, dependencies and README, fetched again when the Galaxy names a new commit. Delivery rules, patterns and permissions see a role by the Galaxy's number, role/16, which its page names. role search and role info ask the Galaxy and leave out roles the rules refuse.
Sign a collection
ansible-galaxy verifies signatures but cannot upload one. Sign the published archive's MANIFEST.json and post the signature, for example from CI:
tar -xzf acme-tools-1.0.0.tar.gz MANIFEST.json
gpg --detach-sign --armor --output MANIFEST.json.asc MANIFEST.json
jq -n --rawfile s MANIFEST.json.asc '{signature: $s}' | curl -fsS -X POST -H "Authorization: Bearer ${QUADER_TOKEN}" \
-H 'Content-Type: application/json' --data @- \
https://quader.example.com/api/v1/projects/web/repositories/ansible-local/ansible/collections/acme.tools/versions/1.0.0/signatures
It needs deploy. Quader checks that the signature is one OpenPGP signature over this version's MANIFEST.json (else 422 signature_invalid) and serves it to collection install --keyring and collection verify. Ask for --required-valid-signature-count +1: with 1 alone the client installs an unsigned version silently. A version takes up to 16 signatures. On a repository that serves only signed versions, readers are refused a version until its signature is posted.
Read a collection's documentation
A version's page has the tabs Documentation and Contents for whoever may read the repository's wiki. Documentation is a tree of the README and Markdown files, Modules, Plugins by type and Roles, with a search over names, descriptions, parameters and return values. A module's page shows what ansible-doc prints, in its order. Each row's link button copies an address ending in #parameter-<name> or #return-<name>. Contents lists everything with its type.
A local repository writes the documentation at publish from the archive's text and runs none of its code; problems show on the version's Import log. A remote fetches it from the upstream while Fetch documentation is on.
Settings
- Who
- the project's Owner, and holders of
repositories:write-config; tombstones need manage
A remote starts at Ansible Galaxy (https://galaxy.ansible.com/api/, further hosts github.com and codeload.github.com for role archives), with a metadata period of 600 seconds and a remembered "not found" of 300. It always verifies each collection archive against the SHA-256 the upstream announces, so checksum policies that skip it are refused. Signatures pass through unchanged; Quader signs none.
| Class | Setting | Default | What it does |
|---|---|---|---|
| Remote | Fetch documentation | on | Fetches each version's documentation from the upstream |
| Remote | Token endpoint URL, Client ID | none, cloud-services |
For a hub behind single sign-on: exchanges the stored offline token for a short-lived one. Never run against a real hub: try a test token first |
The first publish of a name into a local member claims it, so a virtual repository offers no remote version of that name. In the mode Mirror a remote keeps the collections that Mirror only these packages names (acme.*), with every archive, and needs such a bound; roles are not mirrored.
A local repository's Import tasks lists its publishes with their messages; Tombstones lists deleted versions and clears one, after which the number can be published again while caches may still hold the old archive. POST …/reindex rebuilds the version rows from the stored archives (API). The archive limits are the keys of ansible; quader admin import ansible copies an existing Galaxy's collections (Import).
Not available
- An endpoint with exposure rules serves no Ansible repository.
- Roles cannot be published as roles, imported or mirrored.