-
Notifications
You must be signed in to change notification settings - Fork 98
/
exercise134.yaml
38 lines (37 loc) · 1.11 KB
/
exercise134.yaml
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
---
- name: create users on localhost
hosts: localhost
vars_files:
- exercise134-vars.yaml
tasks:
- name: include user and group setup
import_tasks: exercise134-tasks.yaml
- name: create a directory to store the file
file:
name: "{{ item.username }}"
state: directory
loop: "{{ users }}"
- name: copy the local user ssh key to temporary {{ item.username }} key
shell: 'cat /home/{{ item.username }}/.ssh/id_rsa.pub > {{ item.username }}/id_rsa.pub'
loop: "{{ users }}"
- name: verify that file exists
command: ls -l {{ item.username }}/
loop: "{{ users }}"
tags: setuplocal
- name: create users on managed host
hosts: ansible2
vars_files:
- exercise134-vars.yaml
tasks:
- name: include user and group setup
import_tasks: exercise134-tasks.yaml
- name: copy authorized keys
authorized_key:
user: "{{ item.username }}"
key: "{{ lookup('file', './'+ item.username +'/id_rsa.pub') }}"
loop: "{{ users }}"
- name: copy sudoers file
copy:
content: '%admins ALL=(ALL:ALL) NOPASSWD:ALL'
dest: /etc/sudoers.d/admins
tags: setupremote