在哪里定义with_items的列表:引用?

时间:2017-02-16 06:00:29

标签: ansible

在下面的代码中,我可以将traceroute_dest定义为Ansible理解的列表来获取它吗?

---
- name : Traceroute ip addresses
  hosts: all
  gather_facts: no
  tasks:
    - name: "Trace multiple ip addresses"
      raw: "traceroute {{item}}"
      register: trace_result
      with_items: "{{'traceroute_dest'}}"
    - debug: var=trace_result.stdout_lines

1 个答案:

答案 0 :(得分:0)

完整的剧本应该是这样的。

---
- name : Traceroute ip addresses
  hosts: all
  gather_facts: no
  vars_files:
  - 42266085-vars.yml
  tasks:
  - name: "Trace multiple ip addresses"
    raw: "traceroute {{item}}"  
    register: trace_result
    with_items: "{{traceroute_dest}}"
  - debug: var=trace_result
...

定义变量的文件应该是这样的。

---
traceroute_dest: ["119.82.76.111"]