ansible set_fact无法访问 [英] ansible set_fact not accessible

查看:116
本文介绍了ansible set_fact无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这本有趣的剧本

- 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}}"

失败,因为它说未定义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"}

事实证明,我设置的事实可以通过_raw_params进行访问,这等效于

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?

推荐答案

通常,我发现在YAML中,如果周围有空格,它不会将'='解析为字段.试试:

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'

这篇关于ansible set_fact无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆