-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathgalaxy-deploy.yml
58 lines (50 loc) · 1.73 KB
/
galaxy-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
# Automated release playbook for Ansible Collections.
#
# Originally based on Ericsysmin's 2020 blog post. Meant to be used in a GitHub
# Actions CI environment.
#
# Requires a ANSIBLE_GALAXY_TOKEN secret to be configured on the GitHub repo.
#
# Usage:
# ansible-playbook -i 'localhost,' galaxy-deploy.yml \
# -e "github_tag=${{ github.ref }}"
- name: Galaxy deployment playbook
hosts: localhost
connection: local
gather_facts: false
vars:
# Requires github_tag to be set when calling playbook.
release_tag: "{{ github_tag.split('/')[-1] }}"
pre_tasks:
- name: Ensure ANSIBLE_GALAXY_TOKEN is set.
ansible.builtin.fail:
msg: A valid ANSIBLE_GALAXY_TOKEN must be set.
when: "lookup('env', 'ANSIBLE_GALAXY_TOKEN') | length == 0"
- name: Ensure the ~/.ansible directory exists.
ansible.builtin.file:
path: ~/.ansible
state: directory
mode: 0755
- name: Write the Galaxy token to ~/.ansible/galaxy_token
ansible.builtin.copy:
content: |
token: {{ lookup('env', 'ANSIBLE_GALAXY_TOKEN') }}
dest: ~/.ansible/galaxy_token
mode: 0544
no_log: true
tasks:
- name: Ensure the galaxy.yml tag is up to date.
ansible.builtin.lineinfile:
path: galaxy.yml
regexp: "^version:"
line: 'version: "{{ release_tag }}"'
- name: Build the collection.
ansible.builtin.command: ansible-galaxy collection build
register: output
changed_when: "output.rc == 0"
- name: Publish the collection.
ansible.builtin.command: >
ansible-galaxy collection publish ./{{ ansible_namespace }}-{{ collection }}-{{ release_tag }}.tar.gz
register: output
changed_when: "output.rc == 0"