I am building an AMI image on AWS using packer and Ansible. My end goal is to have an AMI image such that when it is built into an EC2 instance, it has my web app running. For me to reach my end goal, I need to configure Nginx server in my AMI. My challenge is I don't have any idea how to get the IP address of the EC2 instance and use it to configure Nginx server. Here is my current configuration of Nginx file:
server {
listen 80;
server_name {{ ansible_default_ipv4.address }};
location / {
include uwsgi_params;
uwsgi_pass unix:/home/ubuntu/Yummy-Recipes/Yummy-Recipes-Ch3/yummy-recipes.sock;
}
}
server_name
should hold the value of the EC2 instance it is running on. If you would like to know more about my code than please feel free to visit my repository on GitHub.
Any help will be highly appreciated.