summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag Wieers <dag@wieers.com>2017-08-24 15:20:59 +0200
committerGitHub <noreply@github.com>2017-08-24 15:20:59 +0200
commit967fbcb662bb8464c00cc1b0268294a7a3726bbd (patch)
treeea97ca73f8d6b2706c2086c3eca24a969e435bc8
parent6fc88992900a97cff3242708865345bddff7d61f (diff)
downloadansible-967fbcb662bb8464c00cc1b0268294a7a3726bbd.tar.gz
xml module: Add backup support (#28595)
This fixes #27949
-rw-r--r--lib/ansible/modules/files/xml.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/ansible/modules/files/xml.py b/lib/ansible/modules/files/xml.py
index 1ccfcacd39..4987fc97fc 100644
--- a/lib/ansible/modules/files/xml.py
+++ b/lib/ansible/modules/files/xml.py
@@ -91,6 +91,12 @@ options:
- Type of input for C(add_children) and C(set_children).
choices: [ xml, yaml ]
default: yaml
+ backup:
+ description:
+ - Create a backup file including the timestamp information so you can get
+ the original file back if you somehow clobbered it incorrectly.
+ type: bool
+ default: 'no'
requirements:
- lxml >= 2.3.0
notes:
@@ -192,6 +198,11 @@ actions:
type: dict
returned: success
sample: {xpath: xpath, namespaces: [namespace1, namespace2], state=present}
+backup_file:
+ description: The name of the backup file that was created
+ type: str
+ returned: when backup=yes
+ sample: /path/to/file.xml.1942.2017-08-24@14:16:01~
count:
description: The count of xpath matches.
type: int
@@ -638,6 +649,9 @@ def finish(module, tree, xpath, namespaces, changed=False, msg="", hitcount=0, m
if module.params['path']:
if not module.check_mode:
+ if module.params['backup']:
+ result['backup_file'] = module.backup_local(module.params['path'])
+
tree.write(module.params['path'], xml_declaration=True, encoding='UTF-8', pretty_print=module.params['pretty_print'])
if module.params['xmlstring']:
@@ -662,7 +676,8 @@ def main():
print_match=dict(type='bool', default=False),
pretty_print=dict(type='bool', default=False),
content=dict(type='str', choices=['attribute', 'text']),
- input_type=dict(type='str', default='yaml', choices=['xml', 'yaml'])
+ input_type=dict(type='str', default='yaml', choices=['xml', 'yaml']),
+ backup=dict(type='bool', default=False),
),
supports_check_mode=True,
mutually_exclusive=[
@@ -690,6 +705,7 @@ def main():
input_type = module.params['input_type']
print_match = module.params['print_match']
count = module.params['count']
+ backup = module.params['backup']
# Check if we have lxml 2.3.0 or newer installed
if not HAS_LXML: