Lab09: Varfolomeeva Anastasia #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 ] | |
| paths: | |
| - 'ansible/**' | |
| - '.github/workflows/ansible-deploy.yml' | |
| pull_request: | |
| branches: [ main, master ] | |
| paths: | |
| - 'ansible/**' | |
| jobs: | |
| lint: | |
| name: Ansible Lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - 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 | |
| working-directory: ansible | |
| run: | | |
| ansible-lint playbooks/*.yml | |
| deploy: | |
| name: Deploy to VM | |
| needs: lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install Ansible and collections | |
| run: | | |
| pip install ansible | |
| ansible-galaxy collection install community.docker | |
| - name: Setup SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| - name: Deploy with Ansible | |
| working-directory: ansible | |
| env: | |
| ANSIBLE_VAULT_PASSWORD: ${{ secrets.ANSIBLE_VAULT_PASSWORD }} | |
| run: | | |
| echo "$ANSIBLE_VAULT_PASSWORD" > /tmp/vault_pass | |
| ansible-playbook playbooks/deploy.yml \ | |
| -i inventory/hosts.ini \ | |
| --vault-password-file /tmp/vault_pass \ | |
| --extra-vars "web_app_wipe=false" | |
| rm /tmp/vault_pass | |
| - name: Verify Deployment | |
| run: | | |
| sleep 10 | |
| curl -f http://${{ secrets.VM_HOST }}:8000/health || exit 1 | |
| curl -f http://${{ secrets.VM_HOST }}:8000/ || exit 1 |