-
Notifications
You must be signed in to change notification settings - Fork 1
124 lines (110 loc) · 3.42 KB
/
deploy_network.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
name: Deploy with Ansible
on:
push:
branches:
- main
env:
ANSIBLE_USER: ${{ secrets.ANSIBLE_USER }}
ANSIBLE_PASSWORD: ${{ secrets.ANSIBLE_PASSWORD }}
GF_SECURITY_ADMIN_USER: ${{ secrets.GF_SECURITY_ADMIN_USER }}
GF_SECURITY_ADMIN_PASSWORD: ${{ secrets.GF_SECURITY_ADMIN_PASSWORD }}
permissions:
contents: read
jobs:
#Job Build
build:
name: Build
runs-on: self-hosted
environment: production
steps:
#Checkout the code
- name: Checkout
uses: actions/checkout@v3
# Install Ansible
- name: Install Ansible
run: |
sudo apt update
sudo apt install -y ansible
# Install python and modules
- name: Install Modules
run: |
sudo apt install python3 python3-pip -y
pip3 install paramiko --no-input
sudo pip3 install ansible-lint
sudo pip3 install --upgrade ansible
sudo pip3 install --upgrade ansible-core
# Install Docker
- name: Install Docker
run: |
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt install docker-ce -y
sudo usermod -aG docker ${USER}
# Set Grafana secrets in .grafana.secret
- name: Set Grafana secrets in .grafana.secret
run: |
cd Monitoring
echo "GF_SECURITY_ADMIN_USER=${{ secrets.GF_SECURITY_ADMIN_USER }}" > .grafana.secret
echo "GF_SECURITY_ADMIN_PASSWORD=${{ secrets.GF_SECURITY_ADMIN_PASSWORD }}" >> .grafana.secret
# Install Monitoring Server
- name: Install Monitoring Server
run: |
cd Monitoring
sudo docker compose up -d
sudo docker compose start
cd snmp-exporter
sudo docker run -i --rm -v $(pwd)/mibs:/opt/mibs -v $(pwd)/generator.yml:/opt/generator.yml -v $(pwd):/opt prom/snmp-generator:main generate
cd ..
sudo docker compose restart
#Job Lint
lint:
name: Lint
runs-on: self-hosted
needs: build
environment: production
steps:
#Checkout the code
- name: Checkout
uses: actions/checkout@v3
# Run ansible-lint
- name: Run ansible-lint
run: |
cd Network
ansible-lint --fix playbook.yml
#Job Test
test:
name: Test
runs-on: self-hosted
needs: lint
environment: production
steps:
#Checkout the code
- name: Checkout
uses: actions/checkout@v3
# Job Deploy
deploy:
name: Deploy
runs-on: self-hosted
needs: test
steps:
# Checkout code from repository
- name: Checkout repository
uses: actions/checkout@v3
# Get commit message
- name: Get Commit Message
id: commit_message
run: |
echo "COMMIT_MSG=$(git log -1 --pretty=format:'%s')" >> $GITHUB_ENV
# Run Ansible Playbook based on commit message
- name: Run Ansible Playbook
run: |
cd Network
if [[ "${{ env.COMMIT_MSG }}" == *"all devices"* ]]; then
ansible-playbook -i inventory playbook.yml
elif [[ "${{ env.COMMIT_MSG }}" == *"ISP"* ]]; then
ansible-playbook -i inventory playbook_ISP.yml
else
echo "No matching playbook found for commit message: ${{ env.COMMIT_MSG }}"
fi