Ansible传递散列以包含模块

Ansible传递散列以包含模块,ansible,ansible-playbook,ansible-2.x,Ansible,Ansible Playbook,Ansible 2.x,我在传递一些复合数据(如YAML映射)作为ansible include模块的输入时遇到问题 这是我的测试: test.yml --- - hosts: all gather_facts: no vars: test_var: test1: hello: world hi: people test2: hello2: world2 hi2: people2 tasks: - deb

我在传递一些复合数据(如YAML映射)作为ansible include模块的输入时遇到问题

这是我的测试:

test.yml

---
- hosts: all
  gather_facts: no
  vars:
    test_var:
      test1:
        hello: world
        hi: people
      test2:
        hello2: world2
        hi2: people2
  tasks:
    - debug: "msg='Variable item.value is: {{ item.value }}'"
      with_dict: "{{ test_var.test1 }}"
    - include: "test1.yml test_variable={{ item.value }}"
      with_dict: "{{ test_var.test1 }}"
test1.yml

---
- debug: "var={{ test_variable }}"
这是输出。请注意带有:
“people”的部分:“变量未定义!”


只需更改test1.yml文件

---
-调试:var=test_变量


这对我来说是正确的。

FYI Get“ERROR:[已弃用]:include+with_items是一项已删除的弃用功能。请更新您的剧本。”对于ansible剧本1.9.3,我使用的是ansible 2.0.1。此功能在ansible 2中重新读取。它在1.6-1.9中被弃用
$ ansible-playbook -i localhost, test.yml

PLAY ***************************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => (item={'value': u'people', 'key': u'hi'}) => {
    "item": {
        "key": "hi",
        "value": "people"
    },
    "msg": "Variable item.value is: people"
}
ok: [localhost] => (item={'value': u'world', 'key': u'hello'}) => {
    "item": {
        "key": "hello",
        "value": "world"
    },
    "msg": "Variable item.value is: world"
}

TASK [include] *****************************************************************
included: /home/mot/jira-scripts/ansible-playbooks/test1.yml for localhost
included: /home/mot/jira-scripts/ansible-playbooks/test1.yml for localhost

TASK [debug] *******************************************************************
ok: [localhost] => {
    "people": "VARIABLE IS NOT DEFINED!"
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "world": "VARIABLE IS NOT DEFINED!"
}

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=0    unreachable=0    failed=0