Skip to content

Commit 3f785b3

Browse files
committed
feat(inventory): allow instances in any state to be fetched optionally
Signed-off-by: Samuel McKendrick <sam.macca9@gmail.com>
1 parent 17db579 commit 3f785b3

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

docs/inventory_plugin/index.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ as simple as the following example:
526526
.. important::
527527
``use_extra_vars`` option will work with ansible v2.11 or higher.
528528

529-
Fetch All Compute Hosts
530-
~~~~~~~~~~~~~~~~~~~~~~~
529+
Fetch All Running Compute Hosts
530+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
531531

532532
To fetch all hosts, your configuration can be as simple as the following
533533
example:
@@ -536,6 +536,18 @@ example:
536536
537537
plugin: oracle.oci.oci
538538
539+
Fetch All Compute Hosts (Regardless Of State)
540+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
541+
542+
To fetch all hosts regardless of the instance's lifecycle state, your configuration would look
543+
similar to the following example:
544+
545+
.. code:: yaml
546+
547+
plugin: oracle.oci.oci
548+
549+
fetch_all_compute_hosts: True
550+
539551
Fetch Only DB Hosts
540552
~~~~~~~~~~~~~~~~~~~
541553

@@ -733,6 +745,7 @@ with more configuration options:
733745
734746
# Compute Hosts (bool type)
735747
fetch_compute_hosts: True
748+
fetch_all_compute_hosts: False
736749
737750
# Process only the primary vnic of a compute instance
738751
primary_vnic_only: True

plugins/inventory/oci.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
fetch_compute_hosts:
125125
description: When set, the compute nodes are fetched. Default value set to True.
126126
type: bool
127+
fetch_all_compute_hosts:
128+
description: When set along with fetch_compute_hosts, compute nodes in any lifecycle state are fetched. Default value set to False.
129+
type: bool
127130
primary_vnic_only:
128131
description: The default behavior of the plugin is to process all VNIC's attached to a compute instance.
129132
This might result in instance having multiple entries. When this parameter is set to True,
@@ -354,6 +357,7 @@
354357
355358
# Compute Hosts (bool type)
356359
fetch_compute_hosts: True
360+
fetch_all_compute_hosts: False
357361
358362
# Process only the primary vnic of a compute instance
359363
primary_vnic_only: True
@@ -1845,16 +1849,20 @@ def get_filtered_instances(self, compartment_ocid, region):
18451849
)
18461850
try:
18471851
compute_client = self.get_compute_client_for_region(region)
1852+
list_all_resources_args = {
1853+
"target_fn": compute_client.list_instances,
1854+
"compartment_id": compartment_ocid,
1855+
"limit": 2000,
1856+
}
1857+
1858+
if not self.get_option("fetch_all_compute_hosts"):
1859+
list_all_resources_args["lifecycle_state"] = "RUNNING"
18481860

18491861
instances = self.get_filtered_resources(
1850-
oci_common_utils.list_all_resources(
1851-
target_fn=compute_client.list_instances,
1852-
compartment_id=compartment_ocid,
1853-
lifecycle_state="RUNNING",
1854-
limit=2000,
1855-
),
1862+
oci_common_utils.list_all_resources(**list_all_resources_args),
18561863
compartment_ocid,
18571864
)
1865+
18581866
return instances
18591867
except ServiceError as ex:
18601868
self.debug(

0 commit comments

Comments
 (0)