-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaccount_create.yml
39 lines (35 loc) · 1.27 KB
/
account_create.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
---
- name: Create Local Account
hosts: "{{ my_server }}"
gather_facts: no
vars:
ansible_svc_account: "{{ account }}"
ansible_home_directory: "{{ home_directory }}"
account_sudoers: "{{ account_sudoer }}"
user_comment: "{{ user_comment }}"
public_key: "{{ public_key }}"
tasks:
- name: Creating the "{{ account }}" user account and the "{{ home_directory }}/{{ account }}" home directory
ansible.builtin.user:
name: "{{ account }}"
home: "{{ home_directory }}/{{ account }}"
create_home: true
comment: "{{ user_comment }}"
password: "{{ password | password_hash('sha512') }}"
state: present
remove: false
system: true
- name: "{{ account }} is included in sudoers.d directory"
when: account_sudoer == 'true'
ansible.builtin.copy:
dest: "/etc/sudoers.d/{{ account }}"
content: "{{ account }} ALL=(ALL) NOPASSWD: ALL\n"
owner: root
group: root
mode: 'ug+rwX,o='
- name: Making sure the public key for the "{{ account }}" account is present
when: public_key != 'false'
ansible.posix.authorized_key:
user: "{{ account }}"
state: present
key: "{{ public_key }}"