diff --git a/lib/ansible/inventory.py b/lib/ansible/inventory.py index 46a5edb589a..05f8001fb12 100644 --- a/lib/ansible/inventory.py +++ b/lib/ansible/inventory.py @@ -82,7 +82,7 @@ class Inventory(object): """ Return the variables associated with this host. """ if host in self._variables: - return self._variables[host] + return self._variables[host].copy() if not self._is_script: return {} diff --git a/test/TestInventory.py b/test/TestInventory.py index 21cccf5fe89..4f48db14f65 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -219,6 +219,15 @@ class TestInventory(unittest.TestCase): assert vars == {"hammer":True} + def test_yaml_change_vars(self): + inventory = self.yaml_inventory() + vars = inventory.get_variables('thor') + + vars["hammer"] = False + + vars = inventory.get_variables('thor') + assert vars == {"hammer":True} + def test_yaml_host_vars(self): inventory = self.yaml_inventory() vars = inventory.get_variables('saturn')