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