So in this demo, we're going to examine both static and dynamic inventories.
However, we're not going to add a host manually to our static inventory.
We're going to import them instead. The dynamic inventory
setup is based on my AWS account. Here,
we'll be using AWS identity and access management interface to get
programmatic access to my AWS account and then build inventory based
on my EC2 instances. Firstly, we will look at importing a static
inventory. And later in this demo, we will examine the dynamic
inventory setup. First, let me create a brand‑new project for this demo.
You will see that this project is using the Git protocol,
and the source control management details are specified in
URL format to my GitHub account.
So when we click on the Inventories tab,
it will display the list of inventories that are currently available.
The inventory list can be sorted by name,
type, and organization, and we just currently have one demo inventory.
So let us add a new inventory, and here we'll enter some basic details.
For now, we'll just give it a name, and we'll click on SAVE, and then we
will go into SOURCES. As you can see, we don't have any sources, so let's
import sources instead of adding them manually.
Now we click on add source. And for the source details, we give the
source of name, and then we'll choose the type of source. You can see
here we have a number of options such as Project,
Amazon EC2, Google Compute Engine, Azure, and VMware. For now,
I don't want to connect to an external source for dynamic inventory, so I will
just select Sourced from a Project. And as you can see, this opens up additional
details for us to enter configuration parameters.
So now I will connect this inventory to the project that I just created,
and this is Project 1 that connects to my GitHub account.
Next, we will select the inventory file that we want to sync from this source.
As you can see,
I only have one inventory file to connect to, and this is
the inventory file that's on my GitHub that contains two
hosts of tower1 and tower2.
Next, I will select UPDATE ON PROJECT UPDATE, so we have access to the
appropriate version, and then I'll click on SAVE. Now we click on Inventory,
and then under the HOSTS section, you will see that we have new sources that I
did not explicitly add with the add host option.
So when we select the HOSTS section, we can see we have tower1
and tower2, which have a status of imported.
Next, we go back to the dashboard, and now you can
see we have a total of three hosts.
Next, let us examine a dynamic inventory setup. Dynamic
inventories fetch information from external sources, and
in our case, it will be AWS.
So there's a bit of prep work for us to do up front, and we need to get
an access key and the secret key from my AWS account.
So to be able to access AWS instance information for our dynamic inventory,
we will need to create an IAM user on my AWS account.
So I'll navigate to the IAM section of my AWS account and select
Users, and then I'll select Add users button. So we'll just fill
out some basic details, and I'll give it a name, and we'll set
permissions for this user account.
I'll actually give this user account admin access, but for this
to work, it could work only with read‑only.
You can also set tags for this for better management.
So once the user has been created, you'll receive a token and a
secret key that we use in Ansible Tower to connect to AWS. Now we go
back to Ansible Tower. And under the RESOURCES, we go to Credentials,
and we create new credentials.
This time at the CREDENTIAL TYPE, we'll select Amazon Web Services. And as
you can see, it is requesting additional information.
So once we have populated details with the token and the secret key,
we are ready to configure the dynamic inventory. Here, we click on
new inventory, and this is going to be our dynamic inventory, and
I'll call this AWS Dynamic.
We'll just select the organization and leave everything else blank.
Just remember to click on SAVE here.
Next, we go into SOURCES, and we click on new sources.
If you recall from just a moment ago when we create a source,
we selected source from a project.
This time,
I'm going to select Amazon EC2 as a source, and then I'm going
to click on SAVE. Next, we want to do a quick sync just to get
the latest information quickly.
And as you can see from the sync source, we have loaded 12 hosts.
Now we click on the HOSTS section, and you will see all the
hosts that are on my test AWS account. And notice under
DESCRIPTION, we have a status of imported.
Now we go back to the dashboard, and you can see we have a
lot more hosts than we did in the past.
These are the hosts that have been dynamically imported for my AWS account.