Team, I am trying to learn how to read results.
I tried searching online but no luck. Basically, I am trying to write a message based on when
condition and it is failing as i might not be following how to intercept.
vars:
local_volume_mount_disks:
- device: /dev/nvme2n1
partitions:
- number: 1
- device: /dev/nvme1n1
partitions:
- number: 1
- device: /dev/sdg
partitions:
- number: 1
- number: 2
task
- name: Check existence of all inventory defined devices on node
shell: "lsblk -p -l | grep {{ item.0.device }}"
loop: "{{ local_volume_mount_disks|subelements('partitions') }}"
register: device_exists
ignore_errors: True
- name: debug device_exists
debug:
var: device_exists
- name: Inventory Device existence condition to continue
fail:
msg: "The command has failed"
when: stderr != ""
#when: item.stderr != ""
#when: item.item.stderr != ""
with_items: device_exists.results
sample output of registered variable
TASK [local_volume_mount : debug device_exists] ********************************
Wednesday 05 May 2021 20:08:07 +0000 (0:00:01.050) 0:00:08.588 *********
ok: [node1] => {
"device_exists": {
"changed": true,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": true,
"cmd": "lsblk -p -l | grep /dev/nvme2n1",
"delta": "0:00:00.018988",
"end": "2021-05-05 20:08:07.193247",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "lsblk -p -l | grep /dev/nvme2n1",
"_uses_shell": true,
"warn": true
}
},
"item": [
{
"device": "/dev/nvme2n1",
"partitions": [
{
"end": "100%",
"number": 1,
"start": "0%",
"storage_class": "ssd-wkr "
}
]
},
{
"end": "100%",
"number": 1,
"start": "0%",
"storage_class": "ssd-wkr "
}
],
"rc": 0,
"start": "2021-05-05 20:08:07.174259",
"stderr": "",
"stderr_lines": [],
"stdout": "/dev/nvme2n1 259:2 0 894.3G 0 disk ",
"stdout_lines": [
"/dev/nvme2n1 259:2 0 894.3G 0 disk "
]
},
{
"ansible_loop_var": "item",
"changed": true,
"cmd": "lsblk -p -l | grep /dev/nvme1n1",
"delta": "0:00:00.015661",
"end": "2021-05-05 20:08:07.375474",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "lsblk -p -l | grep /dev/nvme1n1",
"_uses_shell": true,
"warn": true
}
},
"item": [
{
"device": "/dev/sdg",
"partitions": [
{
"end": "20GiB",
"number": 1,
"start": "1GiB",
"storage_class": "ssd-wkr "
},
{
"end": "40GiB",
"number": 2,
"start": "20GiB",
"storage_class": "ssd-wkr "
}
]
},
{
"end": "40GiB",
"number": 2,
"start": "20GiB",
"storage_class": "ssd-wkr "
}
],
"rc": 0,
"start": "2021-05-05 20:08:07.903902",
"stderr": "",
"stderr_lines": [],
"stdout": "/dev/sdg 8:96 0 9.1T 0 disk ",
"stdout_lines": [
"/dev/sdg 8:96 0 9.1T 0 disk "
]
}
]
}
}
error
TASK [local_volume_mount : Inventory Device existence condition to continue] ***
Wednesday 05 May 2021 20:08:08 +0000 (0:00:00.053) 0:00:08.642 *********
fatal: [node1]: FAILED! => {"msg": "The conditional check 'stderr != \"\"' failed. The error was: error while evaluating conditional (stderr != \"\"): 'stderr' is undefined\n\nThe error appears to be in '/ansible-managed/jenkins-slave/slave0/workspace/run_ansible_playbook/k8s/baremetal/roles/local_volume_mount/tasks/main.yml': line 11, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Inventory Device existence condition to continue\n ^ here\n"}
TASK [local_volume_mount : debug device_exists] ********************************
Wednesday 05 May 2021 20:08:07 +0000 (0:00:01.050) 0:00:08.588 *********
ok: [node1] => {
"device_exists": {
"changed": true,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": true,
"cmd": "lsblk -p -l | grep /dev/nvme2n1",
"delta": "0:00:00.018988",
"end": "2021-05-05 20:08:07.193247",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "lsblk -p -l | grep /dev/nvme2n1",
"_uses_shell": true,
"warn": true
}
},
"item": [
{
"device": "/dev/nvme2n1",
"partitions": [
{
"end": "100%",
"number": 1,
"start": "0%",
"storage_class": "ssd-wkr "
}
]
},
{
"end": "100%",
"number": 1,
"start": "0%",
"storage_class": "ssd-wkr "
}
],
"rc": 0,
"start": "2021-05-05 20:08:07.174259",
"stderr": "",
"stderr_lines": [],
"stdout": "/dev/nvme2n1 259:2 0 894.3G 0 disk ",
"stdout_lines": [
"/dev/nvme2n1 259:2 0 894.3G 0 disk "
]
},
{
"ansible_loop_var": "item",
"changed": true,
"cmd": "lsblk -p -l | grep /dev/nvme1n1",
"delta": "0:00:00.015661",
"end": "2021-05-05 20:08:07.375474",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "lsblk -p -l | grep /dev/nvme1n1",
"_uses_shell": true,
"warn": true
}
},
"item": [
{
"device": "/dev/sdg",
"partitions": [
{
"end": "20GiB",
"number": 1,
"start": "1GiB",
"storage_class": "ssd-wkr "
},
{
"end": "40GiB",
"number": 2,
"start": "20GiB",
"storage_class": "ssd-wkr "
}
]
},
{
"end": "40GiB",
"number": 2,
"start": "20GiB",
"storage_class": "ssd-wkr "
}
],
"rc": 0,
"start": "2021-05-05 20:08:07.903902",
"stderr": "",
"stderr_lines": [],
"stdout": "/dev/sdg 8:96 0 9.1T 0 disk ",
"stdout_lines": [
"/dev/sdg 8:96 0 9.1T 0 disk "
]
}
]
}
}
output
TASK [local_volume_mount : Inventory Device existence condition to continue] ***
Wednesday 05 May 2021 20:08:08 +0000 (0:00:00.053) 0:00:08.642 *********
fatal: [mlwkr1k8s0301d]: FAILED! => {"msg": "The conditional check 'stderr != \"\"' failed. The error was: error while evaluating conditional (stderr != \"\"): 'stderr' is undefined\n\nThe error appears to be in '/ansible-managed/jenkins-slave/slave0/workspace/run_ansible_playbook/k8s/baremetal/roles/local_volume_mount/tasks/main.yml': line 11, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Inventory Device existence condition to continue\n ^ here\n"}
with_items: item.stderr != ""
fatal: [node1]: FAILED! => {"msg": "The conditional check 'item.stderr != \"\"' failed. The error was: error while evaluating conditional (item.stderr != \"\"): 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'stderr'\n\nThe error appears to be in '/ansible-managed/jenkins-slave/slave0/workspace/run_ansible_playbook/k8s/baremetal/roles/local_volume_mount/tasks/main.yml': line 6, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Inventory Device existence condition to continue\n ^ here\n"}