File tree Expand file tree Collapse file tree 2 files changed +7
-17
lines changed
Expand file tree Collapse file tree 2 files changed +7
-17
lines changed Original file line number Diff line number Diff line change @@ -59,26 +59,16 @@ jobs:
5959 python -m pip install --upgrade pip
6060 pip install ansible
6161
62- - name : Create Inventory File
62+ - name : Create SSH Key File
6363 run : |
6464 cd infrastructure/ansible
65- cat > inventory.yml << EOF
66- all:
67- hosts:
68- app_server:
69- ansible_host: ${{ steps.terraform.outputs.public_ip }}
70- ansible_user: ubuntu
71- ansible_ssh_private_key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
72- ansible_ssh_common_args: '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
73- EOF
74- echo "=== Inventory File Contents ==="
75- cat inventory.yml
76- echo "=== End Inventory File ==="
65+ echo "${{ secrets.AWS_EC2_PRIVATE_KEY }}" > vockey.pem
66+ chmod 600 vockey.pem
7767
7868 - name : Run Ansible Playbook
7969 run : |
8070 cd infrastructure/ansible
8171 echo "=== Testing SSH Connection ==="
82- ssh -i <(echo "${{ secrets.AWS_EC2_PRIVATE_KEY }}") -o StrictHostKeyChecking=no ubuntu@${{ steps.terraform.outputs.public_ip }} "echo 'SSH connection successful'"
72+ ssh -i vockey.pem -o StrictHostKeyChecking=no ubuntu@${{ steps.terraform.outputs.public_ip }} "echo 'SSH connection successful'"
8373 echo "=== Running Ansible Playbook ==="
84- ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory.yml playbooks/deploy.yml -vvv
74+ ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory.yml playbooks/deploy.yml -vvv --extra-vars "ansible_host=${{ steps.terraform.outputs.public_ip }}"
Original file line number Diff line number Diff line change 11all :
22 hosts :
33 app_server :
4- ansible_host : " {{ lookup('env', 'EC2_PUBLIC_IP') }}"
4+ ansible_host : " {{ ansible_host }}"
55 ansible_user : ubuntu
6- ansible_ssh_private_key : " {{ lookup('env', 'AWS_EC2_PRIVATE_KEY') }} "
6+ ansible_ssh_private_key_file : vockey.pem
77 ansible_ssh_common_args : " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
You can’t perform that action at this time.
0 commit comments