Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/workflows/ansible-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Ansible Deployment

on:
push:
branches: [main, master]
paths:
- 'ansible/**'
- '!ansible/docs/**'
- '.github/workflows/ansible-deploy.yml'
pull_request:
branches: [main, master]
paths:
- 'ansible/**'
- '!ansible/docs/**'
- '.github/workflows/ansible-deploy.yml'

jobs:
lint:
name: Ansible Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: ansible
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Ansible tooling
run: |
python -m pip install --upgrade pip
pip install ansible ansible-lint
ansible-galaxy collection install community.docker

- name: Run ansible-lint
run: ansible-lint playbooks/*.yml

deploy:
name: Deploy Application
needs: lint
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
defaults:
run:
working-directory: ansible
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Ansible runtime
run: |
python -m pip install --upgrade pip
pip install ansible
ansible-galaxy collection install community.docker

- name: Configure SSH access
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H "${{ secrets.VM_HOST }}" >> ~/.ssh/known_hosts

- name: Build CI inventory
run: |
cat > inventory/ci-hosts.ini <<CI_INVENTORY
[webservers]
target ansible_host=${{ secrets.VM_HOST }} ansible_user=${{ secrets.VM_USER }} ansible_ssh_private_key_file=/home/runner/.ssh/id_rsa
CI_INVENTORY

- name: Deploy with Ansible
env:
ANSIBLE_VAULT_PASSWORD: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
run: |
trap 'rm -f /tmp/vault_pass' EXIT
printf '%s' "$ANSIBLE_VAULT_PASSWORD" > /tmp/vault_pass
ansible-playbook playbooks/deploy.yml \
-i inventory/ci-hosts.ini \
--vault-password-file /tmp/vault_pass

- name: Verify deployment
run: |
sleep 10
ssh -i ~/.ssh/id_rsa "${{ secrets.VM_USER }}@${{ secrets.VM_HOST }}" '
set -e
if curl -fsS "http://127.0.0.1:8000/health" >/dev/null; then
echo "Health check passed on port 8000"
elif curl -fsS "http://127.0.0.1:5000/health" >/dev/null; then
echo "Health check passed on port 5000"
else
echo "Health check failed on ports 8000 and 5000" >&2
docker ps >&2 || true
exit 1
fi
'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Labs](https://img.shields.io/badge/Labs-18-blue)](#labs)
[![Exam](https://img.shields.io/badge/Exam-Optional-green)](#exam-alternative)
[![Duration](https://img.shields.io/badge/Duration-18%20Weeks-lightgrey)](#course-roadmap)
[![Ansible Deployment](https://github.com/sofiakulagina/DevOps-Core-Course/actions/workflows/ansible-deploy.yml/badge.svg)](https://github.com/sofiakulagina/DevOps-Core-Course/actions/workflows/ansible-deploy.yml)

Master **production-grade DevOps practices** through hands-on labs. Build, containerize, deploy, monitor, and scale applications using industry-standard tools.

Expand Down
Loading
Loading