i have this ansible playbook
- name: set var small
set_fact:
iops_price = 41538
ram_price_id = 32438
second_san_price_id = 32926
os_price_id = 49061
when: plan|lower == 'small'
- name: aa
command: echo "{{iops_price}}"
it fails because it says iops_price is not defined, this is the output:
TASK [set var small] ***********************************************************
task path: /home/hanna/proj/db2onc-deploy/db.yml:98
ok: [localhost] => {"ansible_facts": {"_raw_params": "iops_price = 41538 ram_price_id = 32438 second_san_price_id = 32926 os_price_id = 49061"}, "changed": false}
TASK [aa] **********************************************************************
task path: /home/hanna/proj/db2onc-deploy/db.yml:107
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'iops_price' is undefined\n\nThe error appears to have been in '/home/hanna/proj/db2onc-deploy/db.yml': line 107, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: aa\n ^ here\n"}
it turned out that the fact that i set is accessible via _raw_params, which is equivalent to
_raw_params = "iops_price = 41538 ram_price_id = 32438 second_san
_price_id = 32926 os_price_id = 49061"
this is not what i wanted, i actually want to set those individual variables, anybody has any idea why this is happening?
Often I find that in YAML it doesn't parse '=' as fields if there is a space around it. Try:
set_fact:
iops_price=41538
ram_price_id=32438
second_san_price_id=32926
os_price_id=49061
when: plan|lower == 'small'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With