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 ace4ef5 commit ca8f5c4
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions .github/workflows/run-ansible-configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,19 @@ jobs:
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" > .vault_pass
ansible-vault decrypt ansible/secrets.yml --vault-password-file .vault_pass
- name: Check EC2_PRIVATE_IP_1 secret
run: |
if [ -z "${{ secrets.EC2_PRIVATE_IP_1 }}" ]; then
echo "EC2_PRIVATE_IP_1 secret is empty or not set"
exit 1
else
echo "EC2_PRIVATE_IP_1 is set (value not shown for security reasons)"
fi
- name: Add SSH key
run: |
set -x
mkdir -p ~/.ssh
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_ed25519_temp
chmod 600 ~/.ssh/id_ed25519_temp
ssh-keygen -p -f ~/.ssh/id_ed25519_temp -m pem -N "" || echo "ssh-keygen failed"
mv ~/.ssh/id_ed25519_temp ~/.ssh/id_ed25519
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ls -l ~/.ssh/id_ed25519
if ! ssh-keyscan -H "${{ secrets.EC2_PRIVATE_IP_1 }}" >> ~/.ssh/known_hosts 2>&1; then
echo "ssh-keyscan failed. Error output:"
ssh-keyscan -H "${{ secrets.EC2_PRIVATE_IP_1 }}" 2>&1
exit 1
fi
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
ansible-playbook -i inventory ansible/playbook.yml --vault-password-file .vault_pass -e "ansible_ssh_private_key_file=~/.ssh/id_ed25519" -e "ansible_ssh_common_args='-o StrictHostKeyChecking=no'"
- name: Cleanup
if: always()
Expand Down

0 comments on commit ca8f5c4

Please sign in to comment.