diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index bd4bef91b6a5d4..eaddab00765c39 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -506,10 +506,28 @@ def dump_attrs(self): Dumps all attributes to a dictionary ''' attrs = dict() - for name in self._valid_attrs.keys(): - attrs[name] = getattr(self, name) + for (name, attribute) in iteritems(self._valid_attrs): + attr = getattr(self, name) + if attribute.isa == 'class' and attr is not None and hasattr(attr, 'serialize'): + attrs[name] = attr.serialize() + else: + attrs[name] = attr return attrs + def from_attrs(self, attrs): + ''' + Loads attributes from a dictionary + ''' + for (attr, value) in iteritems(attrs): + if attr in self._valid_attrs: + attribute = self._valid_attrs[attr] + if attribute.isa == 'class' and isinstance(value, dict): + obj = attribute.class_type() + obj.deserialize(value) + setattr(self, attr, obj) + else: + setattr(self, attr, value) + def serialize(self): ''' Serializes the object derived from the base object into diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index 630ebfe140b339..09fa6dbe863372 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -332,8 +332,7 @@ def parent_handler_match(target_handler, handler_name): found_task = iterator.get_original_task(original_host, task_result._task) original_task = found_task.copy(exclude_parent=True, exclude_tasks=True) original_task._parent = found_task._parent - for (attr, val) in iteritems(task_result._task_fields): - setattr(original_task, attr, val) + original_task.from_attrs(task_result._task_fields) task_result._host = original_host task_result._task = original_task