Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible set_fact not accessible

Tags:

ansible

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?

like image 531
cakester Avatar asked Jan 06 '23 10:01

cakester


1 Answers

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'
like image 56
jackic23 Avatar answered Jan 14 '23 11:01

jackic23