From 8c3206c99fa940ce58fdcb90e9aa4e0942c32914 Mon Sep 17 00:00:00 2001 From: Jeroen Hoekx Date: Mon, 16 Apr 2012 10:59:34 +0200 Subject: [PATCH] Return a copy of the host variables. --- lib/ansible/inventory.py | 2 +- test/TestInventory.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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')