Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops Ansible:在标准循环中使用变量_Loops_Variables_Ansible - Fatal编程技术网

Loops Ansible:在标准循环中使用变量

Loops Ansible:在标准循环中使用变量,loops,variables,ansible,Loops,Variables,Ansible,我试图在下面描述的示例中使用用户变量 这很好,但是当我尝试注入变量时,它并没有按预期的那样工作。我肯定,我做错了什么 vars: - old: - ens155 - ens160 - new: - eth0 - eth1 我正在尝试生成类似于ens155是eth0和ens160是eth1的回显消息,但此代码显示此消息-[ens155,ens160]是[eth0,eth1] - shell: echo {{ item

我试图在下面描述的示例中使用用户变量

这很好,但是当我尝试注入变量时,它并没有按预期的那样工作。我肯定,我做错了什么

vars:
    - old:
        - ens155
        - ens160
    - new:
        - eth0
        - eth1
我正在尝试生成类似于
ens155是eth0
ens160是eth1
的回显消息,但此代码显示此消息-
[ens155,ens160]是[eth0,eth1]

- shell: echo {{ item.old }} is {{ item.new }}
    with_items:
      - { old: '{{ old }}', new: '{{ new }}' }
我很高兴改变变量的定义方式。

我不得不像下面这样使用

- shell: echo {{ item.0 }} is {{ item.1 }}
  with_together:
    - "{{ old }}"
    - "{{ new }}"

Ansible IRC频道帮了我这个忙。

@MattDavis谢谢,我不知道。我现在会记住这一点。我明天只能接受这个答案,我想应该有一天的差距。
- shell: echo {{ item.0 }} is {{ item.1 }}
  with_together:
    - "{{ old }}"
    - "{{ new }}"