-
---
-
- name: add user
-
hosts: tmp
-
gather_facts: no
-
-
vars_files:
-
- user.yml
-
-
vars_prompt:
-
- name: "sudo"
-
prompt: "do you need sudo ?"
-
private: no
-
default: "no"
-
-
tasks:
-
- name: The add user
-
user: name={{ item.name }} uid={{ item.id }} state=present
-
with_items: users
-
-
-
- name: The user add public key
-
authorized_key: >
-
user={{ item.name }}
-
key="{{ lookup('file', 'item.authorized') }}"
-
with_items: users
-
- name: enable sudo no passwd
-
lineinfile: >
-
regexp='%wheel(.*)NOPASSWD(.*)'
-
state=present
-
line='%wheel ALL=(ALL) NOPASSWD: ALL'
-
dest=/etc/sudoers
-
- name: The user add wheel group
-
user: name={{ item.name }} groups=wheel
-
with_items: users
-
when: 'sudo == "yes"'
[root@ansible-240_199 mUsers]# cat user.yml
---
users:
- {
name: "chengjie",
id: "2036",
authorized: "/ansible/user/ssh_keys/chengjie.pub"
}
- {
name: "liuyu",
id: "1634",
authorized: "/ansible/user/ssh_keys/liuyufeng.pub"
}
Cail_wepiao