mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-07-25 01:04:28 +00:00
With this change we replace zuul.projects with zuul.project that will imply any project which will run the job. Also we read galaxy.yml as vars file to predict packed collection naming for futher upload. Change-Id: I66e27f3026689ad719384203fe66d65f5bca46ce Needed-By: https://review.opendev.org/c/openstack/ansible-config_template/+/846391
79 lines
2.3 KiB
YAML
79 lines
2.3 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: Include galaxy.yml as vars file
|
|
include_vars: "{{ collection_path }}/galaxy.yml"
|
|
|
|
- name: Publish collection to Ansible Galaxy / Automation Hub
|
|
environment:
|
|
ANSIBLE_CONFIG: "{{ _ansiblecfg_tmp.path }}"
|
|
shell: >-
|
|
{{ ansible_galaxy_path }} collection publish -vvv
|
|
{{ build_collection_path }}/{{ namespace }}-{{ name }}-{{ version_tag }}.tar.gz
|
|
|
|
always:
|
|
- name: Shred ansible-galaxy credentials
|
|
command: "shred {{ _ansiblecfg_tmp.path }}"
|