Hello and welcome to our series on using Oracle Linux Automation Manager.
This video shows how to create a dynamic inventory using the Oracle Cloud Infrastructure Ansible
Collection.
Before moving forward, check out our previous video if you are unfamiliar with the Oracle
Cloud Infrastructure Ansible Collection.
So let's get started.
Building off our previous video's git project, we need to add another YAML file.
Following the required naming convention of "someidentifier.oci.yml," create the file
as inventory.oci.yml.
We'll create this in our project's "collections" directory.
Still, the file can be located anywhere in the project, including the root directory.
With the file open for editing, add the entry "plugin: oracle.oci.oci," which enables the
dynamic inventory plugin for Oracle Cloud Infrastructure.
The plugin pulls all the hosts by default when poling instances from our tenancy to
build the inventory.
Depending on your setup, that list could be massive.
Therefore, we should touch on the principle of least privilege.
This means giving a user account or process only those privileges essential to perform
its intended function.
Examples include using the available dynamic inventory options and identity and access
management (IAM) policies to limit the scope and prevent running playbooks against too
many hosts.
Another way to practice the principle of least privilege is by not using "hosts: all" in
your playbooks and specifying specific hosts or groups of hosts.
Although these are all fun topics, we'll stick to discussing the plugin options for this
video.
Specifically, we'll use the highlighted options to filter the compartment and the project
tags.
Since hosts we want to return are in a private network, we'll also include the "hostname_format_preferences"
option.
This option is required as only public IPs are returned by default.
Review the options and save the file.
Then use git to push the changes to your repository.
Now access the Oracle Linux Automation Manager instance by logging into the user interface
using your browser and admin credentials.
Navigate under Resources and click Projects.
Click the sync Icon for our existing OCI Project to ensure the latest code is pulled from our
git repository.
These changes should include our new "inventory.oci.yml" file pushed earlier.
Next, we need to create a new inventory.
Navigate under Resources, then Inventories.
Click the green plus button and then select Inventory from the list of values.
Type "OCI Dynamic" for the name and Default for the organization.
Review the changes and then click the save button.
With the OCI Dynamic Inventory created and information displayed, select the Sources
tab and click the green plus button.
Enter "OCI YAML" for the name and "Sourced from a Project" from the Source list of values.
Then click the search icon next to the Credential text field and select the "OCI" credential
previously created.
Close the pop-up dialog by clicking the select button.
Now, click the search icon next to the Project text field and select our OCI Project.
Once we've picked our project, click the select button to close the pop-up dialog.
Next, enter the full path to the inventory file containing our plugin and options in
the Inventory text field.
Type "collections/inventory.oci.yml" and be sure to exclude the leading slash.
This is the path and file name created earlier within our project.
Review and click the save button.
Once the save completes, scroll down the page and find "OCI YAML" in the list of Sources.
Click the sync icon and wait for the sync job to complete.
The cloud icon will turn green when the job completes.
Next, navigate to the Host tab.
The page displays all the hosts discovered in our compartment based on our set filters.
We can now run our playbooks or an ad-hoc command against these hosts.
But we'll cover that another day.
Thank you for watching.
For additional information on Oracle Linux Automation Manager, access the Oracle Linux
Documentation or Oracle Linux Learning Library.