Skip to content

Instantly share code, notes, and snippets.

@chouseknecht
Last active June 23, 2020 11:34
Show Gist options
  • Save chouseknecht/7a7ee77d4182b7458fa537506d6cb29b to your computer and use it in GitHub Desktop.
Save chouseknecht/7a7ee77d4182b7458fa537506d6cb29b to your computer and use it in GitHub Desktop.
Automated Collection Upload
---
- hosts: all
vars:
galaxy_api_url: http://localhost:5001/api/automation-hub/
galaxy_username: admin
galaxy_password: password
galaxy_namespace:
name: "newswangerd"
description: "Example collections"
galaxy_collection_path: newswangerd-collection_demo-1.0.10.tar.gz
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
copy:
dest: ansible.cfg
content: |
[galaxy]
server_list = local_server
[galaxy_server.local_server]
url={{ galaxy_api_url }}
token={{ galaxy_token }}
- name: publish a collection with ansible-galaxy
shell:
cmd: ANSIBLE_CONFIG=./ansible.cfg ansible-galaxy collection publish -v {{ galaxy_collection_path }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment