【发布时间】:2022-11-22 03:30:05
【问题描述】:
我正在尝试创建一个循环,使用 Ansible 从字典中提取数据并创建资源(例如组),基于 https://docs.ansible.com/ansible/2.9/plugins/lookup/dict.html
# main.yaml
- name: 'Linux | Adding groups'
ansible.builtin.group:
name: "{{ item.key }}"
state: "{{ item.value.state }}"
gid: "{{ item.value.gid }}"
system: False
loop: "{{ lookup('dict', groups) }}"
# vars.yaml
groups:
my_group:
state: present
gid: 1004
上面的代码总是返回以下错误:
fatal: [master-1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'list object' has no attribute 'state'\n\nThe error appears to be in 'path': line 3, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: 'Linux | Adding groups'\n ^ here\n"}
有什么问题的线索吗?
版本:ansible [core 2.13.6]
【问题讨论】:
-
不要将您的群组称为
groups,这是一个保留变量。
标签: ansible