diff --git a/plugins/inventory/instance.py b/plugins/inventory/instance.py index d523c9e2..ba47a1b2 100644 --- a/plugins/inventory/instance.py +++ b/plugins/inventory/instance.py @@ -19,7 +19,7 @@ ) from linode_api4.objects import Instance -DOCUMENTATION = r""" +DOCUMENTATION = """ name: instance author: - Luke Murphy (@decentral1se) @@ -59,7 +59,7 @@ type: list """ -EXAMPLES = r""" +EXAMPLES = """ # Minimal example. `LINODE_API_TOKEN` is exposed in environment. plugin: linode.cloud.instance @@ -209,7 +209,10 @@ def _add_instances_to_groups(self) -> None: def _add_hostvars_for_instances(self) -> None: """Add hostvars for instances in the dynamic inventory.""" for instance in self.instances: - hostvars = instance._raw_json + hostvars = {} + hostvars.update(instance._raw_json) + hostvars["networking_info"] = instance.ips.dict + for hostvar_key in hostvars: self.inventory.set_variable( instance.label, hostvar_key, hostvars[hostvar_key] diff --git a/requirements.txt b/requirements.txt index d96bf1d3..5ef3018c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -linode-api4>=5.15.0 +linode-api4>=5.15.1 polling>=0.3.2 types-requests==2.31.0.10 ansible-specdoc>=0.0.14 diff --git a/tests/integration/targets/instance_inventory/playbooks/test_inventory_filter.yml b/tests/integration/targets/instance_inventory/playbooks/test_inventory_filter.yml index 9e9924d1..e359b26b 100644 --- a/tests/integration/targets/instance_inventory/playbooks/test_inventory_filter.yml +++ b/tests/integration/targets/instance_inventory/playbooks/test_inventory_filter.yml @@ -9,4 +9,7 @@ assert: that: - '"ansible-test-inventory" in hostvars' - - hostvars | length == 1 \ No newline at end of file + - hostvars | length == 1 + - '"networking_info" in hostvars["ansible-test-inventory"]' + - '"ipv4" in hostvars["ansible-test-inventory"]["networking_info"]' + - '"ipv6" in hostvars["ansible-test-inventory"]["networking_info"]' \ No newline at end of file