Workflow for setting up monitoring with ansible #8
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: Workflow for setting up monitoring with ansible | |
| on: | |
| workflow_run: | |
| workflows: ["Deploy infrastructure"] | |
| types: [completed] | |
| jobs: | |
| deploy: | |
| name: Deploy monitoring stack | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Add host to known_hosts | |
| run: | | |
| mkdir -p /home/runner/.ssh | |
| touch /home/runner/.ssh/known_hosts | |
| echo "${{ secrets.SSH_PUBLIC_KEY }}" > /home/runner/.ssh/id_rsa.pub | |
| echo "${{ secrets.SSH_PRIVATE_KEY }}" > /home/runner/.ssh/id_rsa | |
| chmod 600 /home/runner/.ssh/id_rsa | |
| chmod 644 /home/runner/.ssh/id_rsa.pub | |
| ssh-keyscan deltronfr.mooo.com >> /home/runner/.ssh/known_hosts | |
| - name: Install Ansible | |
| shell: bash | |
| run: | | |
| sudo apt update | |
| sudo apt install -y ansible | |
| - name: create ansible config file | |
| run: | | |
| touch infrastructure/ansible/ansible.cfg | |
| echo "[defaults]" > infrastructure/ansible/ansible.cfg | |
| echo "inventory = inventory.ini" >> infrastructure/ansible/ansible.cfg | |
| echo "private_key_file = /home/runner/.ssh/id_rsa" >> infrastructure/ansible/ansible.cfg | |
| echo "remote_user = ${{ secrets.REMOTE_USER }}" >> infrastructure/ansible/ansible.cfg | |
| - name: create inventory file | |
| run: | | |
| echo "[web_servers]" > infrastructure/ansible/inventory.ini | |
| echo "deltronfr.mooo.com" >> infrastructure/ansible/inventory.ini | |
| - name: Load env vars for the playbook | |
| run: | | |
| cd infrastructure/ansible | |
| mkdir group_vars | |
| touch group_vars/all.yaml | |
| echo "${{ secrets.ANS_VARS }}" > group_vars/all.yaml | |
| - name: Run Ansible playbook | |
| run: | | |
| cd infrastructure/ansible | |
| ansible-playbook playbook.yaml |