From 54f1560d3ec0243405cc422a29136071e6fcd4d8 Mon Sep 17 00:00:00 2001 From: Victor Salgado Date: Wed, 16 Sep 2015 16:49:45 -0300 Subject: [PATCH] Fix mutable default argument --- lib/ansible/inventory/dir.py | 5 ++++- lib/ansible/inventory/ini.py | 5 ++++- lib/ansible/inventory/script.py | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/ansible/inventory/dir.py b/lib/ansible/inventory/dir.py index 6159a7207e..b95a18e3f1 100644 --- a/lib/ansible/inventory/dir.py +++ b/lib/ansible/inventory/dir.py @@ -81,7 +81,10 @@ def get_file_parser(hostsfile, groups, loader): class InventoryDirectory(object): ''' Host inventory parser for ansible using a directory of inventories. ''' - def __init__(self, loader, groups=dict(), filename=C.DEFAULT_HOST_LIST): + def __init__(self, loader, groups=None, filename=C.DEFAULT_HOST_LIST): + if groups is None: + groups = dict() + self.names = os.listdir(filename) self.names.sort() self.directory = filename diff --git a/lib/ansible/inventory/ini.py b/lib/ansible/inventory/ini.py index 1e5228d269..a2b7fdec3a 100644 --- a/lib/ansible/inventory/ini.py +++ b/lib/ansible/inventory/ini.py @@ -38,7 +38,10 @@ class InventoryParser(object): with their associated hosts and variable settings. """ - def __init__(self, loader, groups=dict(), filename=C.DEFAULT_HOST_LIST): + def __init__(self, loader, groups=None, filename=C.DEFAULT_HOST_LIST): + if groups is None: + groups = dict() + self._loader = loader self.filename = filename diff --git a/lib/ansible/inventory/script.py b/lib/ansible/inventory/script.py index e9b355cad8..3a59992afd 100644 --- a/lib/ansible/inventory/script.py +++ b/lib/ansible/inventory/script.py @@ -36,7 +36,9 @@ from ansible.module_utils.basic import json_dict_bytes_to_unicode class InventoryScript: ''' Host inventory parser for ansible using external inventory scripts. ''' - def __init__(self, loader, groups=dict(), filename=C.DEFAULT_HOST_LIST): + def __init__(self, loader, groups=None, filename=C.DEFAULT_HOST_LIST): + if groups is None: + groups = dict() self._loader = loader self.groups = groups