Skip to content

Commit

Permalink
inventory: add internal_ip (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
resmo authored Sep 18, 2023
1 parent b7cafff commit 941291f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/86-inventory-internal_ip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- inventory - Added VPC/VPC 2.0 support by adding ``internal_ip`` to the attributes (https://github.com/vultr/ansible-collection-vultr/issues/86).
10 changes: 9 additions & 1 deletion plugins/inventory/vultr.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
description:
- Instance attributes to add as host variables to each host added to inventory.
- See U(https://www.vultr.com/api/#operation/list-instances) for valid values.
- The I(internal_ip) attribute was added in version 1.10.0.
type: list
elements: str
default:
Expand All @@ -77,6 +78,7 @@
- main_ip
- v6_main_ip
- tags
- internal_ip
filters:
description:
- Filter hosts with Jinja2 templates.
Expand Down Expand Up @@ -147,6 +149,11 @@
compose:
ansible_host: vultr_v6_main_ip or vultr_main_ip
# Use the internal IP
plugin: vultr.cloud.vultr
compose:
ansible_host: vultr_internal_ip
# Querying the bare metal instances
plugin: vultr.cloud.vultr
instance_type: bare_metal
Expand All @@ -160,7 +167,8 @@
from ansible.module_utils._text import to_native
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError
from ansible.module_utils.urls import Request
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable, Constructable
from ansible.plugins.inventory import (BaseInventoryPlugin, Cacheable,
Constructable)

from ..module_utils.vultr_v2 import VULTR_USER_AGENT

Expand Down
11 changes: 5 additions & 6 deletions tests/unit/plugins/inventory/test_vultr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@

import json
import os.path
import pytest

import ansible_collections.vultr.cloud.plugins.inventory.vultr as module_under_test
import pytest
from ansible.errors import AnsibleError, AnsibleParserError
from ansible.inventory.data import InventoryData
from ansible.parsing.dataloader import DataLoader
from ansible.template import Templar

import ansible_collections.vultr.cloud.plugins.inventory.vultr as module_under_test
from ansible_collections.vultr.cloud.plugins.inventory.vultr import InventoryModule

from ansible_collections.vultr.cloud.plugins.inventory.vultr import \
InventoryModule

default_options = {
"api_endpoint": "https://test.api.vultr.com/v2",
"api_key": "TEST_VULTR_API_KEY",
"api_results_per_page": 100,
"api_timeout": 60,
"attributes": ["id", "region", "label", "plan", "hostname", "main_ip"],
"attributes": ["id", "region", "label", "plan", "hostname", "main_ip", "tags", "internal_ip"],
"filters": [],
"plugin": "vultr.cloud.vultr",
"variable_prefix": "vultr_",
Expand Down

0 comments on commit 941291f

Please sign in to comment.