在Ansible中使用with_items时,我如何知道何时使用双引号,单引号和大括号? [英] How do I know when to use double quotes, single quotes, and curly brackets when using with_items in Ansible?

查看:407
本文介绍了在Ansible中使用with_items时,我如何知道何时使用双引号,单引号和大括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经在某个地点或其他地点分别为每种"with_items"场景执行任务:

I have had tasks work for each of these 'with_items' scenarios at one point or another:

 with_items: ec2.instances

  with_items: '{{ ec2.instances }}'

 with_items: "{{ ec2.instances }}"

我怎么知道什么时候使用正确的.如果我知道,那我就不会在很多时候陷入反复试验的境地.

How do I know when to use the correct one. If I knew, then I wouldn't be running into a trial-and-error situation as much of the time.

感谢您的帮助!

推荐答案

Ansible< 2.2(从2.1开始弃用)–裸变量:

Ansible < 2.2 (deprecated since 2.1) – bare variables:

with_items: ec2.instances

Ansible> = 2.2 –模板化:

Ansible >= 2.2 – templated:

with_items: '{{ ec2.instances }}'

来自发行说明:

已弃用:

  • 使用_裸变量"处理,现在必须始终将循环项模板化{{}},否则它们将被视为纯字符串.

在这种情况下,单引号或双引号无关紧要.
您可以阅读有关其他SO 问题的报价差异.

Single or double quotes doesn't matter in this case.
You can read about differences in quotes from other SO questions.

这篇关于在Ansible中使用with_items时,我如何知道何时使用双引号,单引号和大括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆