Manually triggered workflow for deployment #870
This file contains 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: Manually triggered workflow for deployment | |
on: | |
workflow_dispatch: | |
inputs: | |
tags: | |
description: 'Ansible playbook tags' | |
required: true | |
push: | |
branches: | |
- master | |
- prod | |
concurrency: | |
group: ${{ github.ref }} | |
jobs: | |
generate-vars: | |
runs-on: ubuntu-latest | |
outputs: | |
ansible_hosts: '${{steps.set_vars.outputs.hosts_file}}' | |
ansible_tags: '${{steps.set_vars.outputs.tags}}' | |
steps: | |
- name: Set vars | |
id: set_vars | |
run: | | |
if [[ "${{github.ref}}" == "refs/heads/prod" ]]; then | |
echo "hosts_file=environments/prod/hosts" >> $GITHUB_OUTPUT | |
elif [[ "${{github.ref}}" == "refs/heads/master" ]]; then | |
echo "hosts_file=environments/dev/hosts" >> $GITHUB_OUTPUT | |
else | |
echo "BRANCH NOT SUPPORTED: ${{github.ref}}" | |
exit 1 | |
fi | |
if [[ "${{github.event_name}}" == "push" ]]; then | |
echo "tags=all" >> $GITHUB_OUTPUT | |
else | |
echo "tags=${{ github.event.inputs.tags }}" >> $GITHUB_OUTPUT | |
fi | |
deploy: | |
runs-on: ubuntu-latest | |
needs: | |
- generate-vars | |
steps: | |
- name: Show deployment branch and tags | |
run: | | |
echo "Deploying from branch: ${{github.ref}}" | |
echo "Deployment for tags: ${{ needs.generate-vars.outputs.ansible_tags }}" | |
- uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Set up Python 3.9 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.9 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install ansible==6.4.0 requests | |
- name: set ansible config secrets | |
env: | |
ANSIBLE_VAULT_PASSWORD: ${{ secrets.ANSIBLE_VAULT_PASSWORD }} | |
run: | | |
echo "$ANSIBLE_VAULT_PASSWORD" > .ansible-vault-password | |
- name: Load ssh key | |
uses: webfactory/ssh-agent@v0.9.0 | |
with: | |
ssh-private-key: ${{ secrets.AUTOMATION_SSH_KEY }} | |
- name: Install/update users and keys | |
run: | | |
ansible-playbook -i ${{ needs.generate-vars.outputs.ansible_hosts }} config-users.yml \ | |
--vault-password-file .ansible-vault-password \ | |
--user automation | |
env: | |
ANSIBLE_HOST_KEY_CHECKING: 'False' | |
- name: Playbook deploy eas3 | |
run: | | |
ansible-playbook -i ${{ needs.generate-vars.outputs.ansible_hosts }} config-eas3.yml \ | |
--vault-password-file .ansible-vault-password \ | |
--tags "${{ needs.generate-vars.outputs.ansible_tags }}" \ | |
--extra-vars "ansible_user=automation" | |
env: | |
ANSIBLE_HOST_KEY_CHECKING: 'False' |