Skip to content

Commit

Permalink
Add networking_info attribute to inventory instances (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai authored Apr 20, 2024
1 parent 42e678d commit f2e553d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions plugins/inventory/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from linode_api4.objects import Instance

DOCUMENTATION = r"""
DOCUMENTATION = """
name: instance
author:
- Luke Murphy (@decentral1se)
Expand Down Expand Up @@ -59,7 +59,7 @@
type: list
"""

EXAMPLES = r"""
EXAMPLES = """
# Minimal example. `LINODE_API_TOKEN` is exposed in environment.
plugin: linode.cloud.instance
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
assert:
that:
- '"ansible-test-inventory" in hostvars'
- hostvars | length == 1
- 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"]'

0 comments on commit f2e553d

Please sign in to comment.