Dzoan nguyen
Implementation Scenario:
Conclusion:
Step 1: Provisioning Infrastructure with Terraform
main.tf
with the following content:us-west-2
region with a given AMI and instance type.main.tf
file is located:main.tf
to output the public IP of the instance:Step 2: Configuring the Instance with Ansible
playbook.yml
with the following content:index.html
file on Debian-based systems.hosts
with the public IP of your instance:<EC2_INSTANCE_PUBLIC_IP>
with the actual IP and update the path to your SSH private key.Step 3: Managing Workflows with Ansible Tower
Scenario Overview
.github/workflows/main.yml
with the following content:main.tf
in your repository:playbook.yml
in an ansible
directory in your repository:Step 1: Generate Terraform Output
main.tf
file, you have already defined an output for the instance IP:Step 2: Create a Terraform Output File
inventory.json
file with the output variables in JSON format.Step 3: Parse Terraform Output in GitHub Actions
terraform output -json
command is used to generate a JSON file with the output data.jq
tool is used to parse the JSON file and extract the EC2 instance's public IP address.ansible_inventory
is created with the necessary host information.-i ansible_inventory
option tells Ansible to use the ansible_inventory
file you created in the previous step.Conclusion
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
CI to EC2
workflow.