summaryrefslogtreecommitdiff
path: root/lib/ansible/utils/helpers.py
diff options
context:
space:
mode:
authorBrian Coca <brian.coca+git@gmail.com>2017-08-28 12:43:09 -0400
committerBrian Coca <brian.coca+git@gmail.com>2017-08-28 12:56:14 -0400
commitf5743396dcffe55c92bcbd31de414214b2edcf9c (patch)
tree8e398417db6399e3de69d2f8bb436284a605e56f /lib/ansible/utils/helpers.py
parent63df0adc17fe8f9a8852881e6e5e99f2c9b5492a (diff)
downloadansible-f5743396dcffe55c92bcbd31de414214b2edcf9c.tar.gz
skip all hidden keys, allow exclude list
Diffstat (limited to 'lib/ansible/utils/helpers.py')
-rw-r--r--lib/ansible/utils/helpers.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/ansible/utils/helpers.py b/lib/ansible/utils/helpers.py
index 997e597fb5..900e0d1ac3 100644
--- a/lib/ansible/utils/helpers.py
+++ b/lib/ansible/utils/helpers.py
@@ -34,8 +34,10 @@ def pct_to_int(value, num_items, min_value=1):
return int(value)
-def object_to_dict(obj):
+def object_to_dict(obj, exclude=None):
"""
- Converts an object into a dict making the properties into keys
+ Converts an object into a dict making the properties into keys, allows excluding certain keys
"""
- return dict((key, getattr(obj, key)) for key in dir(obj) if not key.startswith('__'))
+ if exclude is None or not isinstance(exclude, list):
+ exclude = []
+ return dict((key, getattr(obj, key)) for key in dir(obj) if not (key.startswith('_') or key in exclude))