Skip to content

Commit f419854

Browse files
hkblh
1 parent d3d9052 commit f419854

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

.github/workflows/terraform-deploy.yml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff 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 }}"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
all:
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"

0 commit comments

Comments
 (0)