From 5e1a7e7234cd67fe1c62726599bd98cbeb80832a Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Sun, 7 Oct 2018 19:49:41 -0400 Subject: [PATCH] Create ansible-galaxy-import role Ansible Galaxy has the ability for user to import roles into it. This role will leverage the ansible-galaxy CLI command to do this. We'll login via a github token (sorry only method) then trigger an import on the remote API server. Change-Id: I959c3051403929ef4927cf23fdbef14b45294aa2 Signed-off-by: Paul Belanger --- roles/ansible-galaxy-import/README.rst | 28 +++++++++++++++++++ .../ansible-galaxy-import/defaults/main.yaml | 4 +++ roles/ansible-galaxy-import/tasks/main.yaml | 6 ++++ 3 files changed, 38 insertions(+) create mode 100644 roles/ansible-galaxy-import/README.rst create mode 100644 roles/ansible-galaxy-import/defaults/main.yaml create mode 100644 roles/ansible-galaxy-import/tasks/main.yaml diff --git a/roles/ansible-galaxy-import/README.rst b/roles/ansible-galaxy-import/README.rst new file mode 100644 index 000000000..5d9d6236b --- /dev/null +++ b/roles/ansible-galaxy-import/README.rst @@ -0,0 +1,28 @@ +Import ansible roles into ansible galaxy + +**Role Variables** + +.. zuul:rolevar:: ansible_galaxy_branch + :default: zuul.branch + + The name of a branch to import. + +.. zuul:rolevar:: ansible_galaxy_executable + :default: ansible-galaxy + + Path to ansible-galaxy executable. + +.. zuul:rolevar:: ansible_galaxy_info + + Complex argument which contains the information about the Ansible + Galaxy server as well as the authentication information needed. It + is expected that this argument comes from a `Secret`. + + .. zuul:rolevar:: server + :default: https://galaxy.ansible.com + + The API server destination. + + .. zuul:rolevar:: token + + Identify with github token rather than username and password. diff --git a/roles/ansible-galaxy-import/defaults/main.yaml b/roles/ansible-galaxy-import/defaults/main.yaml new file mode 100644 index 000000000..51c8869a7 --- /dev/null +++ b/roles/ansible-galaxy-import/defaults/main.yaml @@ -0,0 +1,4 @@ +--- +ansible_galaxy_branch: "{{ zuul.branch }}" +ansible_galaxy_executable: ansible-galaxy +ansible_galaxy_server: "{{ ansible_galaxy_info.server|default('https://galaxy.ansible.com') }}" diff --git a/roles/ansible-galaxy-import/tasks/main.yaml b/roles/ansible-galaxy-import/tasks/main.yaml new file mode 100644 index 000000000..d5de23ebe --- /dev/null +++ b/roles/ansible-galaxy-import/tasks/main.yaml @@ -0,0 +1,6 @@ +- name: Login into Ansible Galaxy + command: "{{ ansible_galaxy_executable }} -s {{ ansible_galaxy_server }} login --github-token {{ galaxy_info.token }}" + no_log: True + +- name: Import role into Ansible Galaxy + command: "{{ ansible_galaxy_executable }} -s {{ ansible_galaxy_server }} import --branch {{ ansible_galaxy_branch }} {{ zuul.project['name'].split('/')[0] }} {{ zuul.project['short_name'] }}"