Skip to content

Instantly share code, notes, and snippets.

@chrismeyersfsu
Last active June 11, 2020 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismeyersfsu/9780204a121aa2e72fd61469d1b8020d to your computer and use it in GitHub Desktop.
Save chrismeyersfsu/9780204a121aa2e72fd61469d1b8020d to your computer and use it in GitHub Desktop.
Example operations to upload an ansible collection to galaxy ng.
[galaxy]
server_list = local_server
[galaxy_server.local_server]
url={{ galaxy_api_url }}
token={{ galaxy_token }}
---
- hosts: localhost
vars:
galaxy_api_url: http://localhost:5001/api/automation-hub
galaxy_username: admin
galaxy_password: admin
galaxy_namespace:
name: "foo"
description: "Example collections"
collection: "bar"
gather_facts: False
tasks:
- name: Authenticate and get an API token
uri:
url: "{{ galaxy_api_url }}/v3/auth/token/"
method: POST
url_username: "{{ galaxy_username }}"
url_password: "{{ galaxy_password }}"
force_basic_auth: yes
status_code: 200
body_format: json
return_content: yes
register: galaxy_auth_response
- set_fact:
galaxy_token: "{{ galaxy_auth_response['json']['token'] }}"
- set_fact:
galaxy_auth_header: "Token {{ galaxy_token }}"
- name: Check if the namespace exists
uri:
url: "{{galaxy_api_url}}/v3/namespaces/{{ galaxy_namespace.name }}/"
method: GET
headers:
Authorization: "{{ galaxy_auth_header }}"
register: galaxy_namespace_check
ignore_errors: yes
- name: Create a namespace
uri:
url: "{{galaxy_api_url}}/v3/namespaces/"
method: POST
headers:
Authorization: "{{ galaxy_auth_header }}"
body_format: json
body:
name: "{{ galaxy_namespace.name }}"
description: "{{ galaxy_namespace.description }}"
groups:
- name: "system:partner-engineers"
return_content: yes
status_code: 201
register: galaxy_namespace_response
when: galaxy_namespace_check.status == 404
- debug:
var: galaxy_namespace_response
- name: create ansible.cfg
template:
src: ansible.cfg.j2
dest: ansible.cfg
- name: Create example collection
shell:
cmd: ansible-galaxy collection init --force {{ galaxy_namespace.name }}.{{ galaxy_namespace.collection }}
- name: Create a build of the collection
shell:
cmd: ansible-galaxy collection build . --force
args:
chdir: "{{ galaxy_namespace.name }}/{{ galaxy_namespace.collection }}"
register: results
- name: publish a collection with ansible-galaxy
shell:
cmd: ansible-galaxy collection publish -v {{ results.stdout | regex_replace('^.* at ', '') }}
environment:
ANSIBLE_CONFIG: "./ansible.cfg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment