-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yml
147 lines (131 loc) · 4.55 KB
/
action.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
name: "FreeIPA-Cluster-Test"
description: "Run test playbooks against a FreeIPA cluster"
inputs:
cluster_configuration:
description: "An ipalab-config cluster configuration."
required: true
test_playbooks:
description: "Test playbooks to be executed using the cluster."
required: true
distro:
description: "Default distro. Any accepted by 'ipalab-config'."
required: false
ansible_vars:
description: "Path to file with variables to be used when running the playbooks"
required: false
ansible_requirements:
description: "An Ansible requirements file for the test playbooks."
required: false
shutdown:
description: "Shutdown environment."
required: false
type: boolean
runs:
using: "composite"
steps:
- name: Verify entries
shell: bash
run: |
# Report entry verification
echo "Config: ${{ inputs.cluster_configuration }}"
[ -f "${{ inputs.cluster_configuration }}" ] || echo "Config file not found"
echo "Playbooks:"
for playbook in ${{ inputs.test_playbooks }}
do
echo -n " - ${playbook}"
[ -f "${playbook}" ] && echo ": OK" || echo ": Not found"
done
echo "ansible-requirements: ${{ inputs.ansible_requirements || 'None' }}"
if [ -n "${{ inputs.ansible_requirements }}" ] && [ ! -f "${{ inputs.ansible_requirements }}" ]
then
echo "Requirements file not found."
fi
# Fail step if any entry isn't valid.
[ -f "${{ inputs.cluster_configuration }}" ] || exit 1
for playbook in ${{ inputs.test_playbooks }}
do
[ -f "${playbook}" ] || exit 1
done
if [ -n "${{ inputs.ansible_requirements }}" ] && [ ! -f "${{ inputs.ansible_requirements }}" ]
then
exit 1
fi
- name: Install dependencies
shell: bash
run: |
sudo apt update -y
sudo apt install libkrb5-dev libvirt-dev
sudo apt install software-properties-common
sudo apt install ansible-core podman
- name: Prepare virtual environment
shell: bash
run: |
if [ ! -f venv/bin/activate ]
then
python3 -m venv venv
source venv/bin/activate
pip3 install "podman-compose"
fi
- name: Setup ipalab config
shell: bash
run: |
source venv/bin/activate
pip3 install "ipalab-config>=0.6"
ipalab-config \
-d ${{ inputs.distro || 'fedora-latest' }} \
-o CONFIG_DIR ${{ inputs.cluster_configuration }}
- name: Check if compose is running
id: check_compose
shell: bash
run: |
source venv/bin/activate
echo "compose_up=\
$([ -n "$(podman-compose ps | grep -v "CONTAINER ID")" ] \
&& echo "YES" \
|| echo "NO")" >> $GITHUB_OUTPUT
- name: Create cluster pod
if: ${{ steps.check_compose.vars.output.compose_up }} == "NO"
shell: bash
run: |
source venv/bin/activate
cd CONFIG_DIR
podman-compose -f compose.yml up -d
- name: Ensure '/ect/shadow' is readable
if: ${{ steps.check_compose.vars.output.compose_up }} == "NO"
shell: bash
run: |
source venv/bin/activate
ansible -i CONFIG_DIR/inventory.yml \
-m "ansible.builtin.shell" \
-a "chmod u+r /etc/shadow" all
- name: Deploy cluster
if: ${{ steps.check_compose.vars.output.compose_up }} == "NO"
shell: bash
run: |
source venv/bin/activate
ansible-galaxy collection install -r CONFIG_DIR/requirements.yml
ansible-playbook -i CONFIG_DIR/inventory.yml CONFIG_DIR/playbooks/install-cluster.yml
- name: Install Ansible collections
if: ${{ inputs.ansible_requirements }}
shell: bash
run: |
source venv/bin/activate
ansible-galaxy collection install -r ${{ inputs.ansible_requirements }}
- name: Run Ansible test playboooks
if: ${{ inputs.test_playbooks }}
shell: bash
run: |
source venv/bin/activate
for playbook in ${{ inputs.test_playbooks }}
do
echo "Running playbook: ${playbook}"
[ -n "${{ inputs.ansible_vars }}" ] && extra_opts="-e '@${{ inputs.ansible_vars}}'"
ansible-playbook -i CONFIG_DIR/inventory.yml ${extra_opts} "${playbook}"
done
- name: Shutdown environment
shell: bash
run: |
source venv/bin/activate
cd CONFIG_DIR
[ "${{ inputs.shutdown }}" == "true" ] && podman-compose -f compose.yml down ||: