Ansible - can't refer to module parameter value
If you refer to the structure that debug outputs you can see that myfs.lv
is clearly wrong, because the only keys at the top level are msg
, changed
, and results
.
When you run a task in a loop, the results are stored as a list under the results
key of the registered variable. To access that particular result, you would do something like myfs.results.2.lv
.
Hardcoding an index like this is generally not what you want, though, so you should instead do something to select the result you want. (myfs.results | reject('skipped') | list | first).lv
would retrieve lv
for the first non-skipped result.
Or, of course, you could make this easier on yourself by not looping in the first task:
tasks:
- name: Get filesystem values
lvol:
vg: "{{ mount_dev_split.0 }}"
lv: "{{ mount_dev_split.1 ~ lv_name_suffix }}"
vars:
mount_dev: "{{ (ansible_facts.mounts | selectattr('mount', 'equalto', MT) | list).0.device }}"
mount_dev_split: "{{ (mount_dev | basename).split('-') }}"
lv_name_suffix: "{{ ('-' ~ mount_dev_split.3 | default('')) if '--' in mount_dev else '' }}"
register: myfs
- debug:
msg: "{{ myfs.lv }}"