From 20ca01e486deb1fd3e5047472dfc07c54198a528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=91=D1=82=D1=80?= Date: Sat, 31 Oct 2020 13:51:10 +0100 Subject: [PATCH] Unbreak beadm module (#1105) * Unbreak beadm module * Add a changelog fragment * Module beadm.py: remove regex, use split() everywhere, fix array indexes. * Fix typos * Change array indexes for BE name - according to Oracle documents, the name of BE is in the first column of beadm output on Solaris. * Add 'None' checks in beadm.py --- changelogs/fragments/1105-beadm_bugfix.yaml | 3 ++ plugins/modules/system/beadm.py | 38 ++++++++++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 changelogs/fragments/1105-beadm_bugfix.yaml diff --git a/changelogs/fragments/1105-beadm_bugfix.yaml b/changelogs/fragments/1105-beadm_bugfix.yaml new file mode 100644 index 0000000000..0ff37156c3 --- /dev/null +++ b/changelogs/fragments/1105-beadm_bugfix.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - beadm - fixed issue "list object has no attribute split" (https://github.com/ansible-collections/community.general/issues/791). diff --git a/plugins/modules/system/beadm.py b/plugins/modules/system/beadm.py index 131af6ce65..ab53d0661a 100644 --- a/plugins/modules/system/beadm.py +++ b/plugins/modules/system/beadm.py @@ -165,20 +165,29 @@ class BE(object): if '@' in self.name: for line in out.splitlines(): if self.is_freebsd: - check = re.match(r'.+/({0})\s+\-'.format(self.name), line) - if check: + check = line.split() + if(check == []): + continue + full_name = check[0].split('/') + if(full_name == []): + continue + check[0] = full_name[len(full_name) - 1] + if check[0] == self.name: return check else: check = line.split(';') - if check[1] == self.name: + if check[0] == self.name: return check else: - splitter = '\t' if self.is_freebsd else ';' for line in out.splitlines(): - check = line.split(splitter) - if check[0] == self.name: - return check - + if self.is_freebsd: + check = line.split() + if check[0] == self.name: + return check + else: + check = line.split(';') + if check[0] == self.name: + return check return None def exists(self): @@ -197,11 +206,13 @@ class BE(object): if rc == 0: line = self._find_be_by_name(out) + if line is None: + return False if self.is_freebsd: - if line is not None and 'R' in line.split('\t')[1]: + if 'R' in line[1]: return True else: - if 'R' in line.split(';')[2]: + if 'R' in line[2]: return True return False @@ -250,15 +261,16 @@ class BE(object): if rc == 0: line = self._find_be_by_name(out) + if line is None: + return False if self.is_freebsd: # On FreeBSD, we exclude currently mounted BE on /, as it is # special and can be activated even if it is mounted. That is not # possible with non-root BEs. - if line.split('\t')[2] != '-' and \ - line.split('\t')[2] != '/': + if line[2] != '-' and line[2] != '/': return True else: - if line.split(';')[3]: + if line[3]: return True return False