--- - 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 }}"