documenttion complete #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Ansible Deployment | |
| on: | |
| push: | |
| branches: [main, master, lab06] | |
| paths: | |
| - "ansible/**" | |
| - ".github/workflows/ansible-deploy.yml" | |
| pull_request: | |
| branches: [main, master, lab06] | |
| paths: | |
| - "ansible/**" | |
| jobs: | |
| lint: | |
| name: Ansible Lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: | | |
| pip install ansible ansible-lint | |
| - name: Run ansible-lint | |
| env: | |
| ANSIBLE_VAULT_PASSWORD: ${{ secrets.ANSIBLE_VAULT_PASSWORD }} | |
| run: | | |
| cd ansible | |
| echo "$ANSIBLE_VAULT_PASSWORD" > /tmp/vault_pass | |
| export ANSIBLE_VAULT_PASSWORD_FILE=/tmp/vault_pass | |
| ansible-lint playbooks/*.yml | |
| rm /tmp/vault_pass | |
| deploy: | |
| name: Deploy Application | |
| needs: lint | |
| runs-on: ubuntu-latest | |
| 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 | |
| run: pip install ansible | |
| - name: Setup SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| - name: Deploy with Ansible | |
| env: | |
| ANSIBLE_VAULT_PASSWORD: ${{ secrets.ANSIBLE_VAULT_PASSWORD }} | |
| ANSIBLE_HOST_KEY_CHECKING: False | |
| run: | | |
| cd ansible | |
| echo "$ANSIBLE_VAULT_PASSWORD" > /tmp/vault_pass | |
| ansible-playbook playbooks/deploy.yml \ | |
| -i inventory/hosts.ini \ | |
| --vault-password-file /tmp/vault_pass | |
| rm /tmp/vault_pass | |
| - name: Verify Deployment | |
| run: | | |
| sleep 10 | |
| curl -f http://${{ secrets.VM_HOST }}:5000 || exit 1 | |
| curl -f http://${{ secrets.VM_HOST }}:5000/health || exit 1 |