From 92b0cd8e0ebc9186739216943252ecd4bb34b0d2 Mon Sep 17 00:00:00 2001 From: Nilashish Chakraborty Date: Mon, 28 Jan 2019 20:49:56 +0530 Subject: [PATCH] Add more return values to *_config modules (#50702) * Add more return values to *_config modules Signed-off-by: NilashishC * Add more rv Signed-off-by: NilashishC * Exclude from cli_config docs for now Signed-off-by: NilashishC * Add new rv docs for junos_config Signed-off-by: NilashishC * Fix CI errors Signed-off-by: NilashishC * Support date time for configurable backup path Signed-off-by: NilashishC * Change logic based on configurable path Signed-off-by: NilashishC * Remove unwanted import Signed-off-by: NilashishC * Fix docs Signed-off-by: NilashishC * Add filename rv Signed-off-by: NilashishC * Change dosc filename rv Signed-off-by: NilashishC * Make new rv code more readable Signed-off-by: NilashishC --- lib/ansible/modules/network/eos/eos_config.py | 20 +++++++++++++++++ lib/ansible/modules/network/ios/ios_config.py | 20 +++++++++++++++++ .../modules/network/iosxr/iosxr_config.py | 22 ++++++++++++++++++- .../modules/network/junos/junos_config.py | 20 +++++++++++++++++ .../modules/network/nxos/nxos_config.py | 20 +++++++++++++++++ .../modules/network/vyos/vyos_config.py | 20 +++++++++++++++++ lib/ansible/plugins/action/network.py | 10 +++++++++ 7 files changed, 131 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/network/eos/eos_config.py b/lib/ansible/modules/network/eos/eos_config.py index 726d4e9e937..cfcd9397d28 100644 --- a/lib/ansible/modules/network/eos/eos_config.py +++ b/lib/ansible/modules/network/eos/eos_config.py @@ -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 diff --git a/lib/ansible/modules/network/ios/ios_config.py b/lib/ansible/modules/network/ios/ios_config.py index d7bd899f14b..28bb5fc9325 100644 --- a/lib/ansible/modules/network/ios/ios_config.py +++ b/lib/ansible/modules/network/ios/ios_config.py @@ -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 diff --git a/lib/ansible/modules/network/iosxr/iosxr_config.py b/lib/ansible/modules/network/iosxr/iosxr_config.py index 0583db7b2bf..63fac281fa7 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_config.py +++ b/lib/ansible/modules/network/iosxr/iosxr_config.py @@ -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 diff --git a/lib/ansible/modules/network/junos/junos_config.py b/lib/ansible/modules/network/junos/junos_config.py index e7f252304c1..503dfd1f749 100644 --- a/lib/ansible/modules/network/junos/junos_config.py +++ b/lib/ansible/modules/network/junos/junos_config.py @@ -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 diff --git a/lib/ansible/modules/network/nxos/nxos_config.py b/lib/ansible/modules/network/nxos/nxos_config.py index 3df0199801b..8e84b49ccb5 100644 --- a/lib/ansible/modules/network/nxos/nxos_config.py +++ b/lib/ansible/modules/network/nxos/nxos_config.py @@ -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 diff --git a/lib/ansible/modules/network/vyos/vyos_config.py b/lib/ansible/modules/network/vyos/vyos_config.py index 328a453a1a8..4fb72fb6585 100644 --- a/lib/ansible/modules/network/vyos/vyos_config.py +++ b/lib/ansible/modules/network/vyos/vyos_config.py @@ -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 diff --git a/lib/ansible/plugins/action/network.py b/lib/ansible/plugins/action/network.py index 701035ef7ba..e7d7140ef9e 100644 --- a/lib/ansible/plugins/action/network.py +++ b/lib/ansible/plugins/action/network.py @@ -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()):