-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_user_new.yml
35 lines (29 loc) · 957 Bytes
/
create_user_new.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
---
- hosts: slaves
gather_facts: no
tasks:
- name: get the list of users
local_action: shell ls -al /elk_data/ansible/keys/ |awk '{print $9}'| cut -f1 -d '.'|grep -v '^$'
register: users
- name: create user
user:
name: "{{ item }}"
createhome: yes
state: present
with_items: "{{ users.stdout_lines }}"
become: yes
become_method: "sudo"
- name: create .ssh directory
file: state=directory path=~/.ssh
become: yes
become_user: "{{ item }}"
with_items: "{{ users.stdout_lines }}"
- name: copy ssh key from ACS
copy: src="/elk_data/ansible/keys/{{ item }}.pub" dest=~/.ssh/authorized_keys mode=0600
become: yes
become_user: "{{ item }}"
with_items: "{{ users.stdout_lines }}"
- name: add lines to sudoers file
shell: echo '{{ item }} ALL=(ALL) NOPASSWD{{':'}} ALL' >> /etc/sudoers
become: yes
with_items: "{{ users.stdout_lines }}"