Ansible 使用密码创建用户,如果用户存在则不要更改它
Ansible create user with password, dont change it if user exists
我有一些服务器想用 ansible 管理。目前我需要在所有这些上创建用户帐户。在其中一些上,一些帐户已经存在。我想用默认密码创建用户,但如果用户存在,请不要更改他的密码。
谁能帮我解决这个问题?
这是我的剧本:
---
- hosts: all
become: yes
vars:
sudo_users:
# password is generated through "mkpasswd" command from 'whois' package
- login: user1
password: hashed_password
- login: user1
password: hashed_password
tasks:
- name: Make sure we have a 'sudo' group
group:
name: sudo
state: present
- user:
name: "{{ item.login }}"
#password: "{{ item.password }}"
shell: /bin/bash
groups: "{{ item.login }},sudo"
append: yes
with_items: "{{ sudo_users }}"
来自用户模块的docs:
update_password (added in 1.3) always
/on_create
always
will update passwords if they differ. on_create
will only set the password for newly created users.
我有一些服务器想用 ansible 管理。目前我需要在所有这些上创建用户帐户。在其中一些上,一些帐户已经存在。我想用默认密码创建用户,但如果用户存在,请不要更改他的密码。
谁能帮我解决这个问题?
这是我的剧本:
---
- hosts: all
become: yes
vars:
sudo_users:
# password is generated through "mkpasswd" command from 'whois' package
- login: user1
password: hashed_password
- login: user1
password: hashed_password
tasks:
- name: Make sure we have a 'sudo' group
group:
name: sudo
state: present
- user:
name: "{{ item.login }}"
#password: "{{ item.password }}"
shell: /bin/bash
groups: "{{ item.login }},sudo"
append: yes
with_items: "{{ sudo_users }}"
来自用户模块的docs:
update_password (added in 1.3)
always
/on_create
always
will update passwords if they differ.on_create
will only set the password for newly created users.