Configure Ansible with Nexus

Configure Ansible with Nexus

Configure your Ansible Galaxy client to connect to and authenticate to a Nexus Ansible repository. You must create an Ansible repository in Nexus before configuring your client to connect to it. Refer to Create an Ansible Repository for more details.

Ansible Galaxy can be configured through the following methods:

Configuration Method Best For
Requirements File Installing specific collections, versions, or version ranges from Nexus
Ansible Configuration File Defining reusable Nexus repository servers for Ansible Galaxy commands

Though both the methods support basic authentication which is username and password, Sonatype recommends to use token authentication method for enhanced security.

Requirements File

Use a requirements.yml file when you want to define one or more collections and the Nexus repository source for each collection.

Use the following syntax:

---
collections:
  - name: <namespace>.<collection_name>
    version: "<version>"
    source: <nexus_repository_url>

Where,

Example:

---
collections:
  - name: community.general
    version: "8.0.0"
    source: http://example.nexus.com/repository/ansible-proxy/

- name: myorg.mycollection
    source: http://example.nexus.com/repository/ansible-hosted/

- name: nginxinc.nginx_core
    version: ">=2.0.0,<3.0.0"
    source: http://example.nexus.com/repository/ansible-group/

For protected repositories, include a Base64-encoded token in the requirements file.

---
collections:
  - name: <namespace>.<collection_name>
    source: <nexus_repository_url>
    token: "<base64_token>"

Where,

Example:

---
collections:
  - name: private.collection
    source: http://example.nexus.com/repository/ansible-private/
    token: "XXXXXXXXXXXXXXXXX"

Ansible Configuration File

Use an ansible.cfg file when you want to configure reusable Nexus repository servers for Ansible Galaxy commands.

[defaults]
collections_path = <collections_path>

[galaxy]
server_list = <server_name>

[galaxy_server.<server_name>]
url = <nexus_repository_url>
token = "<base64_token>"

Where,

Example:

[defaults]
collections_path = ./collections

[galaxy]
server_list = nexus_proxy, nexus_hosted

[galaxy_server.nexus_proxy]
url = http://example.nexus.com/repository/ansible-proxy/
token = "XXXXXXXXXXXXXXXXX"

[galaxy_server.nexus_hosted]
url = http://example.nexus.com/repository/ansible-hosted/
token = "XXXXXXXXXXXXXXXXX"

Search results

No results found.