lvg: don't fail if an unknown physical device is encountered (#38446)

Physical devices are listed using 'pvs' command. Then, for
'/dev/dm-*' devices 'dmsetup' command is used to find pv_name.

An error occurs when 'pvs' command list an unknown device:

$ pvs --noheadings -o pv_name,vg_name --separator ';'
  /dev/dm-0;vg_var
  /dev/mapper/sdb3_backups;vg_data_backups
$ dmsetup info -C --noheadings -o name /dev/dm-0
Device dm-0 not found

Then the module fails:
{
  "changed": false,
  "err": "Device dm-0 not found\nCommand failed\n",
  "msg": "Failed executing dmsetup command.",
  "rc": 1
}

This failure can be avoided when the unknown device isn't used in
module parameter 'pvs'.
pull/38449/head
Pilou 6 years ago committed by ansibot
parent d1d15dd025
commit ffee906c54

@ -158,7 +158,12 @@ def main():
# get pv list
pvs_cmd = module.get_bin_path('pvs', True)
rc, current_pvs, err = module.run_command("%s --noheadings -o pv_name,vg_name --separator ';'" % pvs_cmd)
if dev_list:
pvs_filter = ' || '. join(['pv_name = {0}'.format(x) for x in dev_list])
pvs_filter = "--select '%s'" % pvs_filter
else:
pvs_filter = ''
rc, current_pvs, err = module.run_command("%s --noheadings -o pv_name,vg_name --separator ';' %s" % (pvs_cmd, pvs_filter))
if rc != 0:
module.fail_json(msg="Failed executing pvs command.", rc=rc, err=err)

Loading…
Cancel
Save