Skip to content

Commit 48ed20d

Browse files
committed
fix github workflow
1 parent 56b7430 commit 48ed20d

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Ansible Deployment
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
paths:
7+
- 'ansible/**'
8+
- '.github/workflows/ansible-deploy.yml'
9+
10+
jobs:
11+
12+
lint:
13+
name: Ansible Lint
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.12"
24+
25+
- name: Install Ansible
26+
run: |
27+
pip install ansible ansible-lint
28+
29+
- name: Run ansible-lint
30+
run: |
31+
cd ansible
32+
ansible-lint playbooks/*.yml
33+
34+
deploy:
35+
name: Deploy Application
36+
needs: lint
37+
runs-on: ubuntu-latest
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
42+
43+
- name: Setup Python
44+
uses: actions/setup-python@v5
45+
with:
46+
python-version: "3.12"
47+
48+
- name: Install Ansible
49+
run: pip install ansible
50+
51+
- name: Setup SSH
52+
run: |
53+
mkdir -p ~/.ssh
54+
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
55+
chmod 600 ~/.ssh/id_rsa
56+
ssh-keyscan -H ${{ secrets.VM_HOST }} >> ~/.ssh/known_hosts
57+
58+
- name: Deploy with Ansible
59+
run: |
60+
cd ansible
61+
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" > /tmp/vault_pass
62+
ansible-playbook playbooks/deploy.yml \
63+
-i inventory/hosts.ini \
64+
--vault-password-file /tmp/vault_pass
65+
rm /tmp/vault_pass
66+
67+
- name: Verify deployment
68+
run: |
69+
sleep 10
70+
curl -f http://${{ secrets.VM_HOST }}:5000

0 commit comments

Comments
 (0)