f2bf56d984
include_vars works on the controller only, use loading facts
to get variables from galaxy.yml
Change-Id: Idf45354650dea93bd8bdbfa9fa2ba52abda93cc0
(cherry picked from commit 39bb4909ee
)
85 lines
2.5 KiB
YAML
85 lines
2.5 KiB
YAML
---
|
|
- hosts: all
|
|
vars:
|
|
collection_path: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}"
|
|
build_collection_path: /tmp/collection_built/
|
|
ansible_galaxy_path: "~/.local/bin/ansible-galaxy"
|
|
|
|
tasks:
|
|
|
|
- name: Include role for pip
|
|
include_role:
|
|
name: ensure-pip
|
|
|
|
- name: Install ansible
|
|
pip:
|
|
name: ansible-core<2.12
|
|
|
|
- name: Discover tag version
|
|
set_fact:
|
|
version_tag: "{{ zuul.tag|default('no_version', true) }}"
|
|
|
|
- name: Fail if no tag version found
|
|
fail:
|
|
msg: "No tag was found in Zuul vars!"
|
|
when: version_tag == 'no_version'
|
|
|
|
- name: Create a directory for collection
|
|
file:
|
|
state: "{{ item }}"
|
|
path: "{{ build_collection_path }}"
|
|
loop:
|
|
- absent
|
|
- directory
|
|
|
|
- name: Set galaxy.yml for right version from tag
|
|
lineinfile:
|
|
path: '{{ collection_path }}/galaxy.yml'
|
|
regexp: '^version:.*'
|
|
line: 'version: {{ version_tag }}'
|
|
|
|
- name: Build collection
|
|
command: "{{ ansible_galaxy_path }} collection build --output-path {{ build_collection_path }} --force"
|
|
args:
|
|
chdir: "{{ collection_path }}"
|
|
|
|
- name: Publish content to Ansible Galaxy
|
|
block:
|
|
- name: Create ansible.cfg configuration file tempfile
|
|
tempfile:
|
|
state: file
|
|
suffix: .cfg
|
|
register: _ansiblecfg_tmp
|
|
|
|
- name: Create ansible.cfg configuration file
|
|
copy:
|
|
dest: "{{ _ansiblecfg_tmp.path }}"
|
|
mode: 0600
|
|
content: |
|
|
[galaxy]
|
|
server_list = release_galaxy
|
|
|
|
[galaxy_server.release_galaxy]
|
|
url = {{ ansible_galaxy_info.url }}
|
|
token = {{ ansible_galaxy_info.token }}
|
|
|
|
- name: Get content of galaxy.yml
|
|
slurp:
|
|
src: "{{ collection_path }}/galaxy.yml"
|
|
register: galaxy_vars
|
|
|
|
- name: Parse yaml into variable
|
|
set_fact:
|
|
galaxy_yaml: "{{ galaxy_vars['content'] | b64decode | from_yaml }}"
|
|
|
|
- name: Publish collection to Ansible Galaxy / Automation Hub
|
|
environment:
|
|
ANSIBLE_CONFIG: "{{ _ansiblecfg_tmp.path }}"
|
|
shell: >-
|
|
{{ ansible_galaxy_path }} collection publish -vvv
|
|
{{ build_collection_path }}/{{ galaxy_yaml.namespace }}-{{ galaxy_yaml.name }}-{{ version_tag }}.tar.gz
|
|
|
|
always:
|
|
- name: Shred ansible-galaxy credentials
|
|
command: "shred {{ _ansiblecfg_tmp.path }}"
|