Refactor to comply FQCN #3
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: Hetzner Deploy on PR | |
on: | |
pull_request: | |
branches: [ master ] | |
types: [opened, synchronize, reopened] | |
paths-ignore: | |
- 'cidi/**' | |
push: | |
branches: | |
- feature/* | |
- bugfix/* | |
paths-ignore: | |
- 'cidi/**' | |
jobs: | |
build-and-deploy: | |
if: "!startsWith(github.head_ref, 'cidi/')" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c | |
with: | |
python-version: '3.x' # Use the Python version required for your Ansible setup | |
- name: Install Ansible | |
run: pip install ansible | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@69c00852f1304c321337f45a105731218c2d5544 | |
- name: Terraform Initialize | |
run: terraform init | |
env: | |
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }} | |
- name: Terraform validate | |
run: terraform validate | |
env: | |
TF_LOG: INFO | |
- name: Terraform plan | |
run: terraform plan | |
env: | |
TF_LOG: INFO | |
TF_VAR_hcloud_token: ${{ secrets.HCLOUD_TOKEN }} | |
TF_VAR_ansible_ssh_public_key: ${{ secrets.ANSIBLE_SSH_PUBLIC_KEY }} | |
- name: Terraform Apply | |
run: terraform apply -auto-approve | |
env: | |
TF_VAR_hcloud_token: ${{ secrets.HCLOUD_TOKEN }} | |
TF_VAR_ansible_ssh_public_key: ${{ secrets.ANSIBLE_SSH_PUBLIC_KEY }} | |
TF_LOG: INFO | |
- name: Retrieve IP Address | |
id: get-ip | |
run: echo "::set-output name=VM_IP::$(terraform output -raw ip)" | |
- name: Create SSH Key File | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.ANSIBLE_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 400 ~/.ssh/id_rsa | |
- name: Wait for SSH to become available | |
run: | | |
timeout=30 # Timeout in seconds | |
while ! ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa [email protected] 'exit' && [ $timeout -gt 0 ]; do | |
echo "Waiting for SSH to become available..." | |
sleep 5 | |
timeout=$((timeout-5)) | |
done | |
- name: Run Ansible Playbook | |
run: ansible-playbook -i '${{ steps.get-ip.outputs.VM_IP }},' cors-anywhere-playbook.yml --private-key ~/.ssh/id_rsa | |
env: | |
ANSIBLE_PRIVATE_KEY_FILE: ${{ secrets.ANSIBLE_SSH_PRIVATE_KEY }} |