I have searched the group but couldn't find the answer to my problem.
I have a playbook that uses when clause for available space in volume group. I keep getting format errors when trying to run it. I have tried several different variations of the quotes in the statement but can't seem to get it to work.
---
- hosts: all
become: yes
tasks:
- name: Create Logical volume when space is more than 1G
lvol:
vg: vms
lv: lv2
size: 850m
when: 'vms' in ansible_facts['lvm']['vgs'] and ansible_facts['lvm']['vgs']['free_g'] > '1.00'
ERROR! Syntax Error while loading YAML.
did not find expected key
The error appears to be in '/home/automation/plays/logvols.yml': line 10, column 19, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
size: 850m
when: 'vms' in ansible_facts['lvm']['vgs'] and ansible_facts['lvm']['vgs']['free_g'] > 1.00
^ here
This one looks easy to fix. It seems that there is a value started
with a quote, and the YAML parser is expecting to see the line ended
with the same kind of quote. For instance:
when: "ok" in result.stdout
Could be written as:
when: '"ok" in result.stdout'
Or equivalently:
when: "'ok' in result.stdout"
Here is setup module run for ansible_lvm:
ansible1.rtsllc.xyz | SUCCESS => {
"ansible_facts": {
"ansible_lvm": {
"lvs": {
"root": {
"size_g": "35.60",
"vg": "rhel_baseredhat"
},
"swap": {
"size_g": "3.40",
"vg": "rhel_baseredhat"
}
},
"pvs": {
"/dev/sda2": {
"free_g": "0",
"size_g": "39.00",
"vg": "rhel_baseredhat"
},
"/dev/sdb1": {
"free_g": "0.93",
"size_g": "0.93",
"vg": "vms"
}
},
"vgs": {
"rhel_baseredhat": {
"free_g": "0",
"num_lvs": "2",
"num_pvs": "1",
"size_g": "39.00"
},
"vms": {
"free_g": "0.93",
"num_lvs": "0",
"num_pvs": "1",
"size_g": "0.93"
}
}
},
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false
}