47 lines
1.1 KiB
YAML
47 lines
1.1 KiB
YAML
name: Deploy VM and App
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
terraform:
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
working-directory: terraform
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: hashicorp/setup-terraform@v3
|
|
|
|
- name: Terraform init
|
|
run: terraform init
|
|
|
|
- name: Terraform apply
|
|
run: terraform apply -auto-approve
|
|
|
|
- name: Write inventory from output
|
|
run: |
|
|
IP=$(terraform output -raw vm_ipv4_address)
|
|
mkdir -p ../ansible/inventory
|
|
printf '[app]\n%s ansible_user=cloud\n' "$IP" > ../ansible/inventory/hosts.ini
|
|
|
|
- name: Write tags file
|
|
run: |
|
|
TAGS=$(terraform output -json vm_tags)
|
|
echo "$TAGS" > ../terraform/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
|