mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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:
parent
bc09d05917
commit
92b0cd8e0e
7 changed files with 131 additions and 1 deletions
|
@ -269,6 +269,26 @@ backup_path:
|
||||||
returned: when backup is yes
|
returned: when backup is yes
|
||||||
type: str
|
type: str
|
||||||
sample: /playbooks/ansible/backup/eos_config.2016-07-16@22:28:34
|
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._text import to_text
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
|
@ -314,6 +314,26 @@ backup_path:
|
||||||
returned: when backup is yes
|
returned: when backup is yes
|
||||||
type: str
|
type: str
|
||||||
sample: /playbooks/ansible/backup/ios_config.2016-07-16@22:28:34
|
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
|
import json
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,27 @@ backup_path:
|
||||||
description: The full path to the backup file
|
description: The full path to the backup file
|
||||||
returned: when backup is yes
|
returned: when backup is yes
|
||||||
type: str
|
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
|
import re
|
||||||
|
|
||||||
|
|
|
@ -231,6 +231,26 @@ backup_path:
|
||||||
returned: when backup is yes
|
returned: when backup is yes
|
||||||
type: str
|
type: str
|
||||||
sample: /playbooks/ansible/backup/config.2016-07-16@22:28:34
|
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 re
|
||||||
import json
|
import json
|
||||||
|
|
|
@ -281,6 +281,26 @@ backup_path:
|
||||||
returned: when backup is yes
|
returned: when backup is yes
|
||||||
type: str
|
type: str
|
||||||
sample: /playbooks/ansible/backup/nxos_config.2016-07-16@22:28:34
|
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._text import to_text
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
|
@ -161,6 +161,26 @@ backup_path:
|
||||||
returned: when backup is yes
|
returned: when backup is yes
|
||||||
type: str
|
type: str
|
||||||
sample: /playbooks/ansible/backup/vyos_config.2016-07-16@22:28:34
|
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
|
import re
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,16 @@ class ActionModule(_ActionModule):
|
||||||
if copy_result.get('changed', False):
|
if copy_result.get('changed', False):
|
||||||
result['changed'] = copy_result['changed']
|
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
|
# strip out any keys that have two leading and two trailing
|
||||||
# underscore characters
|
# underscore characters
|
||||||
for key in list(result.keys()):
|
for key in list(result.keys()):
|
||||||
|
|
Loading…
Reference in a new issue