Don't call safe_dump if the param is already str

If the input param is already a str, we should write it as-is to the
destination path instead of calling safe_dump on it. The latter will
create a serialized str and it will make future uses of the
inventory/playbook fail on a parse error.

Change-Id: I99c326084e75a5f058928ab7df13fbd7e0a717d7
This commit is contained in:
Flavio Percoco 2017-07-13 13:50:23 +02:00
parent d9beb6d1da
commit 2bc2319c78

View File

@ -94,7 +94,7 @@ class AnsibleAction(actions.Action):
if (isinstance(self._inventory, six.string_types) and
os.path.exists(self._inventory)):
return self._inventory
else:
elif not isinstance(self._inventory, six.string_types):
self._inventory = yaml.safe_dump(self._inventory)
path = os.path.join(self.work_dir, 'inventory.yaml')
@ -266,7 +266,7 @@ class AnsiblePlaybookAction(actions.Action):
if (isinstance(self._inventory, six.string_types) and
os.path.exists(self._inventory)):
return self._inventory
else:
elif not isinstance(self._inventory, six.string_types):
self._inventory = yaml.safe_dump(self._inventory)
path = os.path.join(self.work_dir, 'inventory.yaml')
@ -291,7 +291,7 @@ class AnsiblePlaybookAction(actions.Action):
if (isinstance(self._playbook, six.string_types) and
os.path.exists(self._playbook)):
return self._playbook
else:
elif not isinstance(self._playbook, six.string_types):
self._playbook = yaml.safe_dump(self._playbook)
path = os.path.join(self.work_dir, 'playbook.yaml')