diff --git a/changelogs/fragments/50248-fix-coonfig-backup-glob.yaml b/changelogs/fragments/50248-fix-coonfig-backup-glob.yaml new file mode 100644 index 0000000000..26c1a0afac --- /dev/null +++ b/changelogs/fragments/50248-fix-coonfig-backup-glob.yaml @@ -0,0 +1,4 @@ +bugfixes: +- Change backup file globbing for network _config modules so backing up one host's config + will not delete the backed up config of any host whose hostname is a subset of the first + host's hostname (e.g., switch1 and switch11) diff --git a/lib/ansible/plugins/action/aireos_config.py b/lib/ansible/plugins/action/aireos_config.py index b94be5447a..af4e1f7919 100644 --- a/lib/ansible/plugins/action/aireos_config.py +++ b/lib/ansible/plugins/action/aireos_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/aruba_config.py b/lib/ansible/plugins/action/aruba_config.py index 7c9e1a77ae..f72e023192 100644 --- a/lib/ansible/plugins/action/aruba_config.py +++ b/lib/ansible/plugins/action/aruba_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/asa_config.py b/lib/ansible/plugins/action/asa_config.py index f878ba34d4..0f385dde74 100644 --- a/lib/ansible/plugins/action/asa_config.py +++ b/lib/ansible/plugins/action/asa_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/ce_config.py b/lib/ansible/plugins/action/ce_config.py index e422292e49..f87a18b6e8 100644 --- a/lib/ansible/plugins/action/ce_config.py +++ b/lib/ansible/plugins/action/ce_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/cnos_config.py b/lib/ansible/plugins/action/cnos_config.py index 31699b3db0..ee9d7334db 100644 --- a/lib/ansible/plugins/action/cnos_config.py +++ b/lib/ansible/plugins/action/cnos_config.py @@ -67,7 +67,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/dellos10_config.py b/lib/ansible/plugins/action/dellos10_config.py index b08f6d995d..0ce1322251 100644 --- a/lib/ansible/plugins/action/dellos10_config.py +++ b/lib/ansible/plugins/action/dellos10_config.py @@ -73,7 +73,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/dellos6_config.py b/lib/ansible/plugins/action/dellos6_config.py index 7e7854c429..1f5ba8f3ce 100644 --- a/lib/ansible/plugins/action/dellos6_config.py +++ b/lib/ansible/plugins/action/dellos6_config.py @@ -70,7 +70,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/dellos9_config.py b/lib/ansible/plugins/action/dellos9_config.py index 85902e16e9..4a29ed6342 100644 --- a/lib/ansible/plugins/action/dellos9_config.py +++ b/lib/ansible/plugins/action/dellos9_config.py @@ -73,7 +73,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/edgeos_config.py b/lib/ansible/plugins/action/edgeos_config.py index 7c8334d166..57cb0e27d1 100644 --- a/lib/ansible/plugins/action/edgeos_config.py +++ b/lib/ansible/plugins/action/edgeos_config.py @@ -73,7 +73,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/enos_config.py b/lib/ansible/plugins/action/enos_config.py index 2f74d97e04..69111547b3 100644 --- a/lib/ansible/plugins/action/enos_config.py +++ b/lib/ansible/plugins/action/enos_config.py @@ -68,7 +68,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/eos_config.py b/lib/ansible/plugins/action/eos_config.py index 7ddeed1bb1..2a7df82cee 100644 --- a/lib/ansible/plugins/action/eos_config.py +++ b/lib/ansible/plugins/action/eos_config.py @@ -72,7 +72,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/exos_config.py b/lib/ansible/plugins/action/exos_config.py index 8225a73756..e7849c93a8 100644 --- a/lib/ansible/plugins/action/exos_config.py +++ b/lib/ansible/plugins/action/exos_config.py @@ -72,7 +72,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/ios_config.py b/lib/ansible/plugins/action/ios_config.py index bf47cef9bc..6fde372b14 100644 --- a/lib/ansible/plugins/action/ios_config.py +++ b/lib/ansible/plugins/action/ios_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/iosxr_config.py b/lib/ansible/plugins/action/iosxr_config.py index d862e7fa33..5c110f328a 100644 --- a/lib/ansible/plugins/action/iosxr_config.py +++ b/lib/ansible/plugins/action/iosxr_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/ironware_config.py b/lib/ansible/plugins/action/ironware_config.py index c4cd817043..88c3c4347f 100644 --- a/lib/ansible/plugins/action/ironware_config.py +++ b/lib/ansible/plugins/action/ironware_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/junos_config.py b/lib/ansible/plugins/action/junos_config.py index d382714d1d..101d8846d5 100644 --- a/lib/ansible/plugins/action/junos_config.py +++ b/lib/ansible/plugins/action/junos_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/net_config.py b/lib/ansible/plugins/action/net_config.py index 1fcfd55324..e8c633ce03 100644 --- a/lib/ansible/plugins/action/net_config.py +++ b/lib/ansible/plugins/action/net_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/netconf_config.py b/lib/ansible/plugins/action/netconf_config.py index dbb4a53f0c..6ec21afda5 100644 --- a/lib/ansible/plugins/action/netconf_config.py +++ b/lib/ansible/plugins/action/netconf_config.py @@ -69,7 +69,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/nos_config.py b/lib/ansible/plugins/action/nos_config.py index db7801be20..bdbbd25cc1 100644 --- a/lib/ansible/plugins/action/nos_config.py +++ b/lib/ansible/plugins/action/nos_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/nxos_config.py b/lib/ansible/plugins/action/nxos_config.py index a62b2a85b7..03aed8c7d1 100644 --- a/lib/ansible/plugins/action/nxos_config.py +++ b/lib/ansible/plugins/action/nxos_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/onyx_config.py b/lib/ansible/plugins/action/onyx_config.py index e8c9b3564e..8dbee781e8 100644 --- a/lib/ansible/plugins/action/onyx_config.py +++ b/lib/ansible/plugins/action/onyx_config.py @@ -70,7 +70,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/slxos_config.py b/lib/ansible/plugins/action/slxos_config.py index db7801be20..bdbbd25cc1 100644 --- a/lib/ansible/plugins/action/slxos_config.py +++ b/lib/ansible/plugins/action/slxos_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/sros_config.py b/lib/ansible/plugins/action/sros_config.py index 07ae645564..aa7964bf6a 100644 --- a/lib/ansible/plugins/action/sros_config.py +++ b/lib/ansible/plugins/action/sros_config.py @@ -71,7 +71,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp) diff --git a/lib/ansible/plugins/action/vyos_config.py b/lib/ansible/plugins/action/vyos_config.py index 618e26b93c..550f62b13e 100644 --- a/lib/ansible/plugins/action/vyos_config.py +++ b/lib/ansible/plugins/action/vyos_config.py @@ -72,7 +72,7 @@ class ActionModule(_ActionModule): backup_path = self._get_working_path() + '/backup' if not os.path.exists(backup_path): os.mkdir(backup_path) - for fn in glob.glob('%s/%s*' % (backup_path, host)): + for fn in glob.glob('%s/%s_config.*' % (backup_path, host)): os.remove(fn) tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time())) filename = '%s/%s_config.%s' % (backup_path, host, tstamp)