Skip to content

Commit

Permalink
Fix parsing of lsblk output. (#410)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0d4b3ed)
  • Loading branch information
felixfontein authored and patchback[bot] committed Mar 2, 2022
1 parent 011036b commit f71e4c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/410-luks_device-lsblk-parsing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "luks_device - fix parsing of ``lsblk`` output when device name ends with ``crypt`` (https://github.com/ansible-collections/community.crypto/issues/409, https://github.com/ansible-collections/community.crypto/pull/410)."
14 changes: 6 additions & 8 deletions plugins/modules/luks_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@

# used to get <luks-name> out of lsblk output in format 'crypt <luks-name>'
# regex takes care of any possible blank characters
LUKS_NAME_REGEX = re.compile(r'\s*crypt\s+([^\s]*)\s*')
LUKS_NAME_REGEX = re.compile(r'^crypt\s+([^\s]*)\s*$')
# used to get </luks/device> out of lsblk output
# in format 'device: </luks/device>'
LUKS_DEVICE_REGEX = re.compile(r'\s*device:\s+([^\s]*)\s*')
Expand Down Expand Up @@ -446,13 +446,11 @@ def get_container_name_by_device(self, device):
raise ValueError('Error while obtaining LUKS name for %s: %s'
% (device, result[STDERR]))

m = LUKS_NAME_REGEX.search(result[STDOUT])

try:
name = m.group(1)
except AttributeError:
name = None
return name
for line in result[STDOUT].splitlines(False):
m = LUKS_NAME_REGEX.match(line)
if m:
return m.group(1)
return None

def get_container_device_by_name(self, name):
''' obtain device name based on the LUKS container name
Expand Down

0 comments on commit f71e4c4

Please sign in to comment.