forked from playingfield/clusterlust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh-copy-id.yml
executable file
·35 lines (30 loc) · 962 Bytes
/
ssh-copy-id.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
#!/usr/bin/env ansible-playbook
# Then ./ssh-copy-id.yml -i $ANSIBLE_INVENTORY -k
---
- name: Distribute public ssh-key to ansible inventory
hosts: all:!localhost:!bastion
become: false
gather_facts: false
tasks:
- name: Get home_dir from $HOME
delegate_to: localhost
run_once: true
ansible.builtin.set_fact:
home_dir: "{{ lookup('env', 'HOME') }}"
- name: Selecting public key file
delegate_to: localhost
run_once: true
ansible.builtin.set_fact:
pub_key: "{{ item }}"
with_first_found:
- "{{ home_dir }}/.ssh/authorized_keys"
- "{{ home_dir }}/.ssh/id_ed25519.pub"
- name: Gather facts
ansible.builtin.setup:
filter: ansible_env
- name: Add authorized keys taken from file
ansible.posix.authorized_key:
user: "{{ ansible_env['USER'] }}"
state: present
key: "{{ lookup('file', pub_key) }}"
exclusive: false