Skip to content

Commit

Permalink
Update run-ansible-configs.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Saumya40-codes authored Aug 4, 2024
1 parent 6b4f45c commit e599ff1
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/run-ansible-configs.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
name: Run Ansible Configurations

on:
push:
branches:
- master
paths:
- 'server/**'

- '.github/workflows/run-ansible-configs.yml'
jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -37,14 +35,26 @@ jobs:
- name: Add SSH key
run: |
set -x
mkdir -p ~/.ssh
cat <<EOT > ~/.ssh/id_ed25519
${{ secrets.EC2_SSH_KEY }}
EOT
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_ed25519_temp
ssh-keygen -p -f ~/.ssh/id_ed25519_temp -m pem -N ""
mv ~/.ssh/id_ed25519_temp ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ls -l ~/.ssh/id_ed25519
ssh-keyscan -H ${{ secrets.EC2_PRIVATE_IP_1 }} >> ~/.ssh/known_hosts
cat ~/.ssh/known_hosts
shell: bash

- name: Test SSH connection
run: |
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_PRIVATE_IP_1 }} echo "SSH connection successful"
- name: Run Ansible Playbook
run: |
ansible-playbook -i inventory ansible/playbook.yml --vault-password-file .vault_pass
- name: Cleanup
if: always()
run: |
rm -f ~/.ssh/id_ed25519 .vault_pass

0 comments on commit e599ff1

Please sign in to comment.