In this post, we will discuss how to set up projects and inventories in your Ansible Tower instance.
What is a Tower Project?
Tower projects are a logical collection of Ansible Playbooks that are set up with each other based on what they might be doing or which hosts they might interact with.
Playbooks can be managed within Tower projects by either adding them manually to the project base path on your Tower server, (/var/lib/awx/projects) or by importing them from a source control management system (SCM) that is supported by Tower. Examples of SCMs supported by Tower are Git, Subversion and Mercurial. Managing your projects with an SCM is recommended to ensure that only users with assigned access to the repository can change the Playbook before execution, and for the extra layer of accountability and change control it provides. If your Playbooks are managed by an SCM, update options can be selected to “update on launch”, “delete on update” and “clean”.
If you select “update on launch", Tower will sync each time that project is launched and check in to make sure that the most up-to-date Playbooks are running. Selecting "clean" clears out old managed files and unmanaged files in the directory for that project. Selecting “delete on update” will delete the local repository in its entirety prior to performing an update.
1. Click the Project link at the top of your Tower instance and select the “+Add” button.
2. Upon arriving to the new project page, name the project and select what organization within your instance will be using this project.
3. Select the source for this project, whether that be locally or through an SCM. (Don’t forget that the base path where projects are stored is /var/lib/awx/projects)
4. Once you have declared the source, you can select "clean", "delete on update" and "update on launch" from the SCM update options.
Once you have the correct source and you have selected the options you need, hit the save button and you will be returned to the Projects page with your new project listed.
What is a Tower Inventory?
Now that you have set up a Tower project, all you need is some hosts (nodes) to automate and you will be cooking with gas. Within Tower, the hosts that you interact with are set up as collections within Tower called inventories. Tower divides inventories into groups and the groups are what contain the actual hosts. Groups can be sourced manually by adding the IPs and hostnames into Tower, imported from an Ansible hosts file, or they can be sourced from one of Ansible Tower’s supported cloud providers.
If you choose to go the route of using a dynamic inventory source (which is a very popular path), don’t forget you will need to create credentials to get access to your specific provider if your inventory source is a cloud source. If you have an external source of truth for your infrastructure (whether it is a cloud provider or a local CMDB), it is best to define an inventory sync process and use Tower’s support for dynamic inventory. This ensures your inventory is always up to date.
For more on what is included with dynamic inventories in Tower, check out these docs.
Adding a Static Inventory
For the purpose of this blog post, I will go through the steps to add a static inventory to demonstrate the process.
1. To start, from the Tower dashboard, select the inventories header. This will take you to the inventories page where all of your current inventories will be displayed.
2. Once there, select the green “+Add” button to create a new inventory.
3. This will open the “Create Inventory” page where you will need to name the inventory and also select which organization it will fall under.
4. Once that is done, select save. (Note: You are not done, your inventory still needs hosts!)
5. Once you have saved, that specific inventory page will be displayed. (Since this is a brand new one, it will be empty.)
6. To add a host, simply select the green button that says “+Add Host”
7. This will open the create host page. This is where you will input the host name and any variable definitions and values to be applied to the selected host.
Note that any variables entered must be in either YAML or JSON syntax. You can use the radio buttons above the text box to switch between the two.
Once you have added everything necessary for that host (hostname and any variables), select save and that will add the host to the inventory. You can now view your newly added host in your inventory!
I hope this post helps you get started setting up your Tower projects and inventories smoothly.
In the next post in the series, we will go over the steps and requirements needed before you run your first Playbook in Tower, what you will be looking at while the job is running, and the ways you can examine previous job runs to help improve overall performance.
Have any questions from this blog or previous blogs in our Getting Started series? Join one of our monthly "Getting Started Q&A" webinars over here.