forked from master-afip/ansible-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpropagate_ssh_key.yml
48 lines (46 loc) · 1.18 KB
/
propagate_ssh_key.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
40
41
42
43
44
45
46
---
# resolved : https://bugzilla.redhat.com/show_bug.cgi?id=1539142
#
- hosts: all,!local
become: true
vars:
myuser: justin
tasks:
- name: add user justin
user:
name: "{{ myuser }}"
shell: /bin/bash
password: "{{ '12345678' | password_hash('sha512') }}"
groups: adm
append: yes
- name: Create a directory for ssh
file:
path: "/home/{{ myuser }}/.ssh"
owner: "{{ myuser}}"
group: "{{ myuser}}"
state: directory
mode: '0700'
- name: create a file know_authorized
file:
path: "/home/{{ myuser }}/.ssh/authorized_keys"
owner: "{{ myuser}}"
group: "{{ myuser}}"
state: touch
mode: '0600'
- hosts: slave
become: true
vars:
myuser: justin
tasks:
- name: create ssh key on admin user {{ myuser }}
delegate_to: target2
openssh_keypair:
path: "/home/{{myuser}}/.ssh/id_rsa"
owner: "{{ myuser }}"
group: "{{ myuser }}"
register: ssh_key
- name: add public key
lineinfile:
path: "/home/{{ myuser }}/.ssh/authorized_keys"
state: present
line: "{{ssh_key['public_key'] }}"