Add more return values to *_config modules (#50702)

* Add more return values to *_config modules

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Add more rv

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Exclude from cli_config docs for now

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Add new rv docs for junos_config

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Fix CI errors

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Support date time for configurable backup path

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Change logic based on configurable path

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Remove unwanted import

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Fix docs

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Add filename rv

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Change dosc filename rv

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Make new rv code more readable

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>
This commit is contained in:
Nilashish Chakraborty 2019-01-28 20:49:56 +05:30 committed by GitHub
parent bc09d05917
commit 92b0cd8e0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 131 additions and 1 deletions

View file

@ -269,6 +269,26 @@ backup_path:
returned: when backup is yes
type: str
sample: /playbooks/ansible/backup/eos_config.2016-07-16@22:28:34
filename:
description: The name of the backup file
returned: when backup is yes and filename is not specified in backup options
type: str
sample: eos_config.2016-07-16@22:28:34
shortname:
description: The full path to the backup file excluding the timestamp
returned: when backup is yes and filename is not specified in backup options
type: str
sample: /playbooks/ansible/backup/eos_config
date:
description: The date extracted from the backup file name
returned: when backup is yes
type: str
sample: "2016-07-16"
time:
description: The time extracted from the backup file name
returned: when backup is yes
type: str
sample: "22:28:34"
"""
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule

View file

@ -314,6 +314,26 @@ backup_path:
returned: when backup is yes
type: str
sample: /playbooks/ansible/backup/ios_config.2016-07-16@22:28:34
filename:
description: The name of the backup file
returned: when backup is yes and filename is not specified in backup options
type: str
sample: ios_config.2016-07-16@22:28:34
shortname:
description: The full path to the backup file excluding the timestamp
returned: when backup is yes and filename is not specified in backup options
type: str
sample: /playbooks/ansible/backup/ios_config
date:
description: The date extracted from the backup file name
returned: when backup is yes
type: str
sample: "2016-07-16"
time:
description: The time extracted from the backup file name
returned: when backup is yes
type: str
sample: "22:28:34"
"""
import json

View file

@ -212,7 +212,27 @@ backup_path:
description: The full path to the backup file
returned: when backup is yes
type: str
sample: /playbooks/ansible/backup/iosxr01.2016-07-16@22:28:34
sample: /playbooks/ansible/backup/iosxr01_config.2016-07-16@22:28:34
filename:
description: The name of the backup file
returned: when backup is yes and filename is not specified in backup options
type: str
sample: iosxr01_config.2016-07-16@22:28:34
shortname:
description: The full path to the backup file excluding the timestamp
returned: when backup is yes and filename is not specified in backup options
type: str
sample: /playbooks/ansible/backup/iosxr01_config
date:
description: The date extracted from the backup file name
returned: when backup is yes
type: str
sample: "2016-07-16"
time:
description: The time extracted from the backup file name
returned: when backup is yes
type: str
sample: "22:28:34"
"""
import re

View file

@ -231,6 +231,26 @@ backup_path:
returned: when backup is yes
type: str
sample: /playbooks/ansible/backup/config.2016-07-16@22:28:34
filename:
description: The name of the backup file
returned: when backup is yes and filename is not specified in backup options
type: str
sample: junos01_config.2016-07-16@22:28:34
shortname:
description: The full path to the backup file excluding the timestamp
returned: when backup is yes and filename is not specified in backup options
type: str
sample: /playbooks/ansible/backup/junos01_config
date:
description: The date extracted from the backup file name
returned: when backup is yes
type: str
sample: "2016-07-16"
time:
description: The time extracted from the backup file name
returned: when backup is yes
type: str
sample: "22:28:34"
"""
import re
import json

View file

@ -281,6 +281,26 @@ backup_path:
returned: when backup is yes
type: str
sample: /playbooks/ansible/backup/nxos_config.2016-07-16@22:28:34
filename:
description: The name of the backup file
returned: when backup is yes and filename is not specified in backup options
type: str
sample: nxos_config.2016-07-16@22:28:34
shortname:
description: The full path to the backup file excluding the timestamp
returned: when backup is yes and filename is not specified in backup options
type: str
sample: /playbooks/ansible/backup/nxos_config
date:
description: The date extracted from the backup file name
returned: when backup is yes
type: str
sample: "2016-07-16"
time:
description: The time extracted from the backup file name
returned: when backup is yes
type: str
sample: "22:28:34"
"""
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule

View file

@ -161,6 +161,26 @@ backup_path:
returned: when backup is yes
type: str
sample: /playbooks/ansible/backup/vyos_config.2016-07-16@22:28:34
filename:
description: The name of the backup file
returned: when backup is yes and filename is not specified in backup options
type: str
sample: vyos_config.2016-07-16@22:28:34
shortname:
description: The full path to the backup file excluding the timestamp
returned: when backup is yes and filename is not specified in backup options
type: str
sample: /playbooks/ansible/backup/vyos_config
date:
description: The date extracted from the backup file name
returned: when backup is yes
type: str
sample: "2016-07-16"
time:
description: The time extracted from the backup file name
returned: when backup is yes
type: str
sample: "22:28:34"
"""
import re

View file

@ -110,6 +110,16 @@ class ActionModule(_ActionModule):
if copy_result.get('changed', False):
result['changed'] = copy_result['changed']
if backup_options and backup_options.get('filename'):
result['date'] = time.strftime('%Y-%m-%d', time.gmtime(os.stat(result['backup_path']).st_ctime))
result['time'] = time.strftime('%H:%M:%S', time.gmtime(os.stat(result['backup_path']).st_ctime))
else:
result['date'] = tstamp.split('@')[0]
result['time'] = tstamp.split('@')[1]
result['shortname'] = result['backup_path'][::-1].split('.', 1)[1][::-1]
result['filename'] = result['backup_path'].split('/')[-1]
# strip out any keys that have two leading and two trailing
# underscore characters
for key in list(result.keys()):