Ansible:YAML属性为变量

时间:2018-04-05 15:23:26

标签: ansible jinja2

我有这本Ansible剧本:

  vars:
    a: "key"
    b: "value"
    something:
      "{{ a }}": "{{ b }}"
  tasks:
    - name: debug
      debug:
        msg: "{{ something | to_nice_yaml }}"

输出结果为:

ok: [localhost] => {
    "msg": "'{{ a }}': value\n"
}

如何将其设为key: value而不是{{ a }}: value

1 个答案:

答案 0 :(得分:1)

您可以尝试set_fact:

tasks:
    - set_fact: something="{{ a }}:{{ b }}"