Automating the deployment of infrastructure to AWS by using Packer to build machine images, and Ansible as a provisioner to the packer script.
- If you’re using Homebrew on a macOS, install Packer using
$ brew install packer - If you're using Chocolatey on a windows machine, use
$ choco install packer
- Using the variables in
.env.samplefile as guide, create a.envfile and supply the information specific to your AWS account.
- Run the bash script in the root directory to source the
.envfile and run packertemplate.jsonfile.
- From your AWS console (ensure you're in the same region the image was created), click on Services at the top menu and select EC2.
- Navigate to the left hand menu, under IMAGES, click on AMI.
- From the list of images presented to you, identify the image you just created and select it. Click on launch.
- Choose an instance type, and then choose Next: Configure Instance Details. t2.micro will be selected by default since the image was built with this instance_type.
- Click Next: Add Storage
- Click Next: Add Tags
- Add tags (optional) and proceed to create security group.
- In the port range column, input the port your app is running on.
- Set the source IP to 0.0.0.0/0 to allow traffic from all sources.
- Click "Review and Launch" to review your settings.
- Then click launch.
- Select an existing key pair or create a new key pair, select the acknowledge agreement box, and then choose Launch Instances.
- Navigate to EC2 dashboard and click on instances to view the instance you just created.
- Click on the instance from the list presented.
- Copy the IP address and past it in your browser URL to access the application.
- Read up the article on medium Using Packer & Ansible for Configuration and Change Management