tested template
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
name: Deploy VM and App
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tfvars_file:
|
||||
@@ -13,45 +15,64 @@ on:
|
||||
- multi.tfvars.example
|
||||
|
||||
jobs:
|
||||
terraform:
|
||||
terraform-ansible-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: terraform
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: hashicorp/setup-terraform@v3
|
||||
- name: Check files & Select tfvars
|
||||
shell: bash
|
||||
run: |
|
||||
#rm ansible/inventory/inventory.yml
|
||||
mkdir -p ansible/inventory
|
||||
cd terraform
|
||||
#rm vm_data.yml
|
||||
cp "${{ inputs.tfvars_file || 'single.tfvars.example' }}" terraform.tfvars
|
||||
|
||||
- name: Select tfvars
|
||||
run: cp "${{ inputs.tfvars_file }}" terraform.tfvars
|
||||
- uses: hashicorp/setup-terraform@v4
|
||||
|
||||
- name: Check path
|
||||
run: pwd
|
||||
|
||||
- name: Terraform init
|
||||
run: terraform init
|
||||
working-directory: "terraform"
|
||||
|
||||
- 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
|
||||
working-directory: "terraform"
|
||||
|
||||
- name: Install Ansible
|
||||
shell: bash
|
||||
run: |
|
||||
python3 -m pip install --upgrade pip
|
||||
pip install ansible community.docker
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ansible rsync
|
||||
|
||||
- name: Deploy app
|
||||
run: ansible-playbook -i ansible/inventory/hosts.ini ansible/playbooks/deploy.yml
|
||||
- name: Set up SSH
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/vlans_rsa
|
||||
chmod 600 ~/.ssh/vlans_rsa
|
||||
cat > ~/.ssh/config <<'EOF'
|
||||
Host *
|
||||
StrictHostKeyChecking no
|
||||
UserKnownHostsFile=/dev/null
|
||||
EOF
|
||||
|
||||
- name: Run playbook
|
||||
run: |
|
||||
ansible-playbook ansible/playbooks/docker_copy.yml -i ansible/inventory/inventory.yml -u cloud --private-key ~/.ssh/vlans_rsa
|
||||
|
||||
- name: Configure Git
|
||||
run: |
|
||||
git config user.name "git-bot"
|
||||
git config user.email "got-bot@text.com"
|
||||
|
||||
- name: Commit and push to Gitea
|
||||
run: |
|
||||
git remote set-url origin https://$GITEA_USERNAME:${{ secrets.GIT_BOT_TOKEN }}@tea.charcarservices.uk/CC/N8N.git
|
||||
git add terraform/vm_data.yml ansible/inventory/inventory.yml
|
||||
git diff --cached --quiet || git commit -m "chore: update terraform outputs"
|
||||
git push origin HEAD:main
|
||||
env:
|
||||
GITEA_USERNAME: git-bot # or your bot account
|
||||
|
||||
Reference in New Issue
Block a user