58 lines
1.4 KiB
YAML
58 lines
1.4 KiB
YAML
name: Deploy VM and App
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
tfvars_file:
|
|
description: "Which tfvars file to use"
|
|
required: true
|
|
default: "single.tfvars.example"
|
|
type: choice
|
|
options:
|
|
- single.tfvars.example
|
|
- multi.tfvars.example
|
|
|
|
jobs:
|
|
terraform:
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
working-directory: terraform
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: hashicorp/setup-terraform@v3
|
|
|
|
- name: Select tfvars
|
|
run: cp "${{ inputs.tfvars_file }}" terraform.tfvars
|
|
|
|
- name: Terraform init
|
|
run: terraform init
|
|
|
|
- name: Terraform apply
|
|
run: terraform apply -auto-approve
|
|
|
|
- name: Write inventory
|
|
run: |
|
|
mkdir -p ../ansible/inventory
|
|
terraform output -json vm_ipv4_addresses | jq -r '
|
|
to_entries[] | "[app]\n\(.value) ansible_user=cloud"
|
|
' > ../ansible/inventory/hosts.ini
|
|
|
|
- name: Write tags
|
|
run: terraform output -json vm_tags > ../ansible/vm_tags.json
|
|
|
|
deploy:
|
|
needs: terraform
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Install Ansible
|
|
run: |
|
|
python3 -m pip install --upgrade pip
|
|
pip install ansible community.docker
|
|
|
|
- name: Deploy app
|
|
run: ansible-playbook -i ansible/inventory/hosts.ini ansible/playbooks/deploy.yml
|