Refactor ansible-apply.yaml and inventory/hosts, add ANSIBLE_USER and SSH_AUTH_SOCK environment variables, and update Terraform Apply script to handle multiple hosts

This commit is contained in:
2024-09-26 20:22:02 +02:00
parent a6c8ab5127
commit 93cc8a3a64
+10 -2
View File
@@ -89,6 +89,14 @@ jobs:
- name: Terraform Apply
env:
VAULT_MASTER_PASSWORD: ${{ secrets.VAULT_MASTER_PASSWORD }}
ANSIBLE_USER: ${{ secrets.ANSIBLE_USER }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
cd terraform/k8sapps
sectool exec terraform apply --auto-approve
for HOST in $TRUSTED_HOSTS; do
ssh -f -N -L 16443:localhost:16443 $ANSIBLE_USER@$HOST
# override hosts address in kube config
sed -i "s/server: https:\/\/$HOST:16443/server: https:\/\/localhost:16443/g" ~/.kube/config
cd terraform/k8sapps
sectool exec terraform apply --auto-approve
pkill -f "ssh -f -N -L 16443:localhost:16443 $ANSIBLE_USER@$HOST"
done