-
Notifications
You must be signed in to change notification settings - Fork 26
129 lines (107 loc) · 4.44 KB
/
ansible-run.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
---
name: Ansible Run
# on: [push]
on:
pull_request:
types: [opened, synchronize, ready_for_review, edited]
jobs:
setup:
runs-on: ubuntu-latest
outputs:
inventories: ${{ steps.output-inventories.outputs.inventories }}
steps:
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
- name: Adding Known Hosts
run: ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Wait for other runs to stop
run: |
while true; do
VM=$(ssh ${{ secrets.SSH_OPTIONS }} -t -p ${{ secrets.SSH_PORT }} -l ${{ secrets.SSH_USER }} ${{ secrets.SSH_HOST }} "ls -l /tmp/run-lock 2>/dev/null | wc -l")
if [ "$VM" -gt 0 ]; then
echo "Another job is running, waiting 60 seconds..."
sleep 60s
else
ssh ${{ secrets.SSH_OPTIONS }} -p ${{ secrets.SSH_PORT }} -l ${{ secrets.SSH_USER }} ${{ secrets.SSH_HOST }} "touch /tmp/run-lock"
break
fi
done
- uses: actions/checkout@v2
- name: Deploy folder
run: |
ssh ${{ secrets.SSH_OPTIONS }} -p ${{ secrets.SSH_PORT }} -l ${{ secrets.SSH_USER }} ${{ secrets.SSH_HOST }} "mkdir -p ~/${{ github.sha }}"
rsync -aH -e "ssh ${{ secrets.SSH_OPTIONS }} -p ${{ secrets.SSH_PORT }} -l ${{ secrets.SSH_USER }}" ./ ${{ secrets.SSH_HOST }}:~/${{ github.sha }}/
- name: output inventories
id: output-inventories
run: |
echo "::set-output name=inventories::$(find examples/inventory-test-* | sort -u | jq -R -s -c 'split("\n")[:-1]')"
run:
# Run the test inside a centos8 container
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
max-parallel: 4
matrix:
inventory: ${{fromJSON(needs.setup.outputs.inventories)}}
steps:
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
- name: Adding Known Hosts
run: ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
# Run all inventory files in the repo
- name: Run Terrible validation
run: |
ssh ${{ secrets.SSH_OPTIONS }} -t -p ${{ secrets.SSH_PORT }} -l ${{ secrets.SSH_USER }} ${{ secrets.SSH_HOST }} <<EOF
set -e
export PY_COLORS=1
export ANSIBLE_FORCE_COLOR=1
cd ~/${{ github.sha }}
echo "VALIDATE $inventory ******************************************************************"
echo "ansible-playbook -i ${{ matrix.inventory }} -u root main.yml"
ansible-playbook -i ${{ matrix.inventory }} -u root main.yml
EOF
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
# Run all inventory files in the repo
- name: Run Terrible cleanup
if: ${{ always() }}
run: |
ssh ${{ secrets.SSH_OPTIONS }} -t -p ${{ secrets.SSH_PORT }} -l ${{ secrets.SSH_USER }} ${{ secrets.SSH_HOST }} <<EOF
set -e
export PY_COLORS=1
export ANSIBLE_FORCE_COLOR=1
cd ~/${{ github.sha }}
echo "VALIDATE $inventory ******************************************************************"
echo "ansible-playbook -i ${{ matrix.inventory }} -u root main.yml --tags purge"
ansible-playbook -i ${{ matrix.inventory }} -u root main.yml --tags purge
EOF
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
cleanup:
# Run the test inside a centos8 container
runs-on: ubuntu-latest
needs: run
if: always()
steps:
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
- name: Adding Known Hosts
run: ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Cleanup Folder
run: |
ssh ${{ secrets.SSH_OPTIONS }} -p ${{ secrets.SSH_PORT }} -l ${{ secrets.SSH_USER }} ${{ secrets.SSH_HOST }} "rm -rf ~/${{ github.sha }} ~/.terrible ~/.ssh/known_hosts /tmp/run-lock /tmp/*.tfplan"
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'