mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
INI inventory plugin: add documentation about variable types (#25798)
* INI inventory: check variable types * INI inventory: add doc about variable types Fixes #25784
This commit is contained in:
@@ -22,10 +22,10 @@ __metaclass__ = type
|
||||
import string
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils._text import to_text
|
||||
|
||||
from ansible.inventory.manager import InventoryManager, split_host_pattern
|
||||
from ansible.vars.manager import VariableManager
|
||||
|
||||
from units.mock.loader import DictDataLoader
|
||||
|
||||
@@ -109,7 +109,7 @@ class TestInventory(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class InventoryDefaultGroup(unittest.TestCase):
|
||||
class IniInventory(unittest.TestCase):
|
||||
|
||||
def test_empty_inventory(self):
|
||||
inventory = self._get_inventory('')
|
||||
@@ -142,6 +142,20 @@ class InventoryDefaultGroup(unittest.TestCase):
|
||||
host5
|
||||
""")
|
||||
|
||||
def test_ini_variables_stringify(self):
|
||||
values = ['string', 'no', 'No', 'false', 'FALSE', [], False, 0]
|
||||
|
||||
inventory_content = "host1 "
|
||||
inventory_content += ' '.join(['var%s=%s' % (i, to_text(x)) for i, x in enumerate(values)])
|
||||
inventory = self._get_inventory(inventory_content)
|
||||
|
||||
variables = inventory.get_host('host1').vars
|
||||
for i in range(len(values)):
|
||||
if isinstance(values[i], string_types):
|
||||
self.assertIsInstance(variables['var%s' % i], string_types)
|
||||
else:
|
||||
self.assertIsInstance(variables['var%s' % i], type(values[i]))
|
||||
|
||||
def _get_inventory(self, inventory_content):
|
||||
|
||||
fake_loader = DictDataLoader({__file__: inventory_content})
|
||||
|
||||
Reference in New Issue
Block a user