ansible - 请解释 Ansible 中 "item"的用法

标签 ansible

我发现一些使用单词 "{{ item.id }}"{{ item.sg_name }} 的 AWS Ansible 代码。

我不明白“item”命令是如何工作的。

最佳答案

item 不是命令,而是由 Ansible 在使用 loops 的任务中自动创建和填充的变量。 .

在以下示例中:

- debug:
    msg: "{{ item }}"
  with_items:
    - first
    - second

该任务将运行两次:第一次将变量item设置为first,第二次将second设置为second

此外,如果循环的元素是字典,您可以使用点符号引用它们的键,如示例所示:

- debug:
    msg: "{{ item.my_value }}"
  with_items:
    - ny_element: first
      my_value: 1
    - my_element: second
      my_value: 2

关于ansible - 请解释 Ansible 中 "item"的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46724196/

相关文章:

linux - 如何在 Ubuntu 上固定 Rabbitmq 版本?

Ansible 在变量内使用变量

Ansible-安装固定到主要版本的软件包

Ansible 角色 : change file extension

pip - Ansible pip 模块 : name package and umask 0022 Fatal error: invalid literal for int() with base 8: '18' umask must be an octal integer

python - 将 Docker 存储库添加到 APT 源时出现错误

Ansible:如何从另一个剧本调用剧本?

ansible - AWX - 使用 Ansible 集合

ansible - 从 ansible playbook 只运行一个任务和处理程序

Ansible:将注册变量保存到文件