ansible share image

In our previous article, we explored how to use the Red Hat Ansible Automation Platform CLI to create an Elastic Compute Cloud (EC2) in Amazon Web Services (AWS). This time, we will take things a step further and leverage the power of the Ansible Automation Platform to automate the process. Ansible Automation Platform is a powerful tool that enables you to manage your infrastructure more efficiently with less manual intervention.

Follow the series:

Part 1: How to create an EC2 instance on AWS using Ansible CLI

Part 2: How to create an EC2 instance in AWS using Ansible Automation

Part 3: How to create EC2 instance on AWS using Ansible workflow

By using Ansible Automation Platform, we can create a streamlined process for deploying EC2s in AWS, reducing errors and saving time. In this article, we will dive into the details of how to use Ansible Automation Platform to create instances in AWS and explore the benefits of using this powerful automation tool.

How to create credentials

Follow these steps to create your credentials as referenced in Figure 1:

  • Navigate to the Credentials Tab under Resources in Ansible Automation Platform.
  • Select Amazon Web Services under Credential type.
  • Add your access key and secret key, then save it.
    A screenshot of the Ansible create AWS credentials page.
    Figure 1: The Ansible create credentials page.

Creating and configuring the project

Follow these steps to create and configure your project:

  • Install Ansible Automation Platform by following the instructions in the article How to install Red Hat Ansible Automation Platform on RHEL 9.
  • Log in to Ansible Automation Platform portal in the browser.
  • Navigate to the Projects tab under Resources in the left pane.
  • Click on the Add button to create a new project.
  • Enter a name for the project and choose Git as the source control type with the URL https://github.com/redhat-developer-demos/ansible-automation-platform-cloud-solutions in the Source Control URL field. (If you're interested in checking out the Ansible playbooks, you can find them on GitHub.)
  • Save the changes and wait for the operation to complete successfully, as shown in Figure 2.
A screenshot of the form for configuring the project source control in Ansible.
Figure 2: Configuring the project source control.

Creating and configuring the job template

Follow these steps to create and configure the job template:

  • Go to the Templates tab under Resources in the left pane.
  • Click on the Add button and select Job template from the options.
  • Enter a name for the job you want to create.
  • In the Inventory section, select the Demo-Inventory or Default inventory.
  • In the Project section, click on the project name you previously created and select the AWS/create_ec2instance.yml file.

Configuring the variables and execution environment

  • Click on the Variables section.
  • Add the variables as follows:

---

region: ap-south-1

instance_type: t3.micro

ami: ami-0f9d9a251c1a44858

key_name: ansible-demo

vpc_name: ansible-vpc-test

cidr_block: "10.10.0.0/16"

cidr: "10.10.0.0/24"
  • Select the credentials you previously created under the selected category, as shown in Figure 3.
A screenshot of the form for AWS credentials secure authentication.
Figure 3: Selecting pre-configured AWS credentials for secure authentication.
  • Select the default execution environment, as shown in Figure 4. 
A screenshot of where to Select the default execution environment in Ansible.
Figure 4: Selecting the default execution environment.
  • Save your changes by clicking the Save button.
  • Finally, launch the job by clicking on the Launch button.
  • Once the job is launched using Ansible Automation Platform, the system will generate an output that should be similar to Figure 5.
A screenshot of the output from the job in Ansible.
Figure 5: Output from the job.

The output will display the status of the job and the progress of the instance creation process, as shown in Figure 6.

A screenshot of the EC2 instance created in AWS.
Figure 6: Showing the EC2 Instance in AWS.

What’s next?

In this article, we explored how to use Ansible Automation Platform to create an EC2 instance in Amazon Web Services. We demonstrated how Ansible Automation Platform can streamline the process of deploying EC2s in AWS, making it more efficient and less error-prone. By using the power of automation, we can save time and free up resources to focus on other important tasks.

To explore more of what Ansible Automation Platform has to offer, visit the official website to download and get started. Additionally, there are various e-books available to help you explore the capabilities of Ansible Automation Platform such as:

There is also a cheat sheet for WiFi automation with Ansible and SD that provides a quick reference for network automation tasks.

In the final article of this series, we go even further by exploring how to simplify the process of creating an EC2 instance in AWS using workflow templates to optimize infrastructure management. Workflow templates standardize the process of creating instances and reduce the amount of manual intervention required. 

Last updated: January 11, 2024