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

查看:26
本文介绍了在 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 }}'

来自发行说明:

已删除已弃用:

  • with_ 'bare variable' 处理,现在循环项必须始终模板化 {{ }} 否则它们将被视为纯字符串.

单引号或双引号在这种情况下无关紧要.
您可以阅读其他 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天全站免登陆