Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(inventory): optionally allow instances in any state to be fetched #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions docs/inventory_plugin/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ as simple as the following example:
.. important::
``use_extra_vars`` option will work with ansible v2.11 or higher.

Fetch All Compute Hosts
~~~~~~~~~~~~~~~~~~~~~~~
Fetch All Running Compute Hosts
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To fetch all hosts, your configuration can be as simple as the following
example:
Expand All @@ -536,6 +536,18 @@ example:

plugin: oracle.oci.oci

Fetch All Compute Hosts (Regardless Of State)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To fetch all hosts regardless of the instance's lifecycle state, your configuration would look
similar to the following example:

.. code:: yaml

plugin: oracle.oci.oci

fetch_all_compute_hosts: True

Fetch Only DB Hosts
~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -733,6 +745,7 @@ with more configuration options:

# Compute Hosts (bool type)
fetch_compute_hosts: True
fetch_all_compute_hosts: False

# Process only the primary vnic of a compute instance
primary_vnic_only: True
Expand Down
20 changes: 14 additions & 6 deletions plugins/inventory/oci.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
fetch_compute_hosts:
description: When set, the compute nodes are fetched. Default value set to True.
type: bool
fetch_all_compute_hosts:
description: When set along with fetch_compute_hosts, compute nodes in any lifecycle state are fetched. Default value set to False.
type: bool
primary_vnic_only:
description: The default behavior of the plugin is to process all VNIC's attached to a compute instance.
This might result in instance having multiple entries. When this parameter is set to True,
Expand Down Expand Up @@ -354,6 +357,7 @@

# Compute Hosts (bool type)
fetch_compute_hosts: True
fetch_all_compute_hosts: False

# Process only the primary vnic of a compute instance
primary_vnic_only: True
Expand Down Expand Up @@ -1845,16 +1849,20 @@ def get_filtered_instances(self, compartment_ocid, region):
)
try:
compute_client = self.get_compute_client_for_region(region)
list_all_resources_args = {
"target_fn": compute_client.list_instances,
"compartment_id": compartment_ocid,
"limit": 2000,
}

if not self.get_option("fetch_all_compute_hosts"):
list_all_resources_args["lifecycle_state"] = "RUNNING"

instances = self.get_filtered_resources(
oci_common_utils.list_all_resources(
target_fn=compute_client.list_instances,
compartment_id=compartment_ocid,
lifecycle_state="RUNNING",
limit=2000,
),
oci_common_utils.list_all_resources(**list_all_resources_args),
compartment_ocid,
)

return instances
except ServiceError as ex:
self.debug(
Expand Down