gpt4 book ai didi

Ansible with_items 第二个列表作为条件

转载 作者:行者123 更新时间:2023-12-04 08:15:23 25 4
gpt4 key购买 nike

我有我在每个系统上创建的完整用户列表。如何为每个系统创建一个条件来创建仅在 group_vars 中定义的用户变量 system_users ?
变量:users.yml

users:
user1:
username: user1
password: "example"
user2:
username: user2
password: "example"
user3:
username: user3
password: "example"
group_var: dev-systems.yml
system_users:
- "user1"
- "user2"
任务:main.yml
- name: Create users and change password
user:
name: "{{ users[item].username }}"
password: "{{ users[item].password }}"
shell: /bin/bash
state: present
update_password: on_create
become: true
with_items: "{{ users }}"
主机
[dev-systems]
example-system.local

最佳答案

尝试这个

- name: Create users and change password
user:
name: "{{ item.username }}"
password: "{{ item.password }}"
shell: /bin/bash
state: present
update_password: on_create
become: true
loop: "{{ system_users|map('extract',users)|list }}"

关于Ansible with_items 第二个列表作为条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65731252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com