feat: add workflow for deploying playbook on merge

This commit is contained in:
Ditmar Visser
2025-06-04 11:58:35 +00:00
parent 7ba2b487bb
commit 232556075d
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,36 @@
name: Ansible CI/CD
on:
pull_request:
branches:
- main
types: [closed]
jobs:
deploy:
name: Deploy Ansible Playbook
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up SSH
run: |
echo "${{ secrets.DEVHOST_SSH_PRIVATE_KEY }}" > private_key.pem
chmod 600 private_key.pem
- name: Install Ansible
shell: bash
run: |
sudo apt update
sudo apt install -y ansible
- name: Run Ansible Playbook
env:
ANSIBLE_USER: ${{ secrets.ANSIBLE_USER }}
ANSIBLE_HOST_KEY_CHECKING: False
run: |
ansible-playbook -i opdracht-2/inventory.ini opdracht-2/nginx.yml --private-key private_key.pem -u ${{ secrets.DEVHOST_ANSIBLE_USER }}