Samuli Silvius | 6fd5670 | 2019-02-19 18:07:02 +0200 | [diff] [blame] | 1 | --- |
| 2 | - name: "Check and generate key if needed" |
| 3 | block: |
| 4 | - name: ssh dir |
| 5 | file: |
| 6 | path: "{{ ssh_dir }}" |
| 7 | state: directory |
| 8 | mode: 0700 |
| 9 | |
| 10 | - name: check ssh pub key exists |
| 11 | stat: |
| 12 | path: '{{ private_key }}.pub' |
| 13 | register: p |
| 14 | |
| 15 | - name: generate ssh keys |
| 16 | command: ssh-keygen -f {{ private_key }} -t rsa -N '' |
| 17 | when: not p.stat.exists |
| 18 | vars: |
| 19 | private_key: "{{ ssh_dir }}/{{ offline_ssh_key_file_name }}" |
| 20 | delegate_to: localhost |
| 21 | run_once: true |
| 22 | |
| 23 | - name: Setup authorized_keys file |
| 24 | authorized_key: |
| 25 | user: root |
| 26 | state: present |
| 27 | key: "{{ lookup('file', public_key) }}" |
Samuli Silvius | 6fd5670 | 2019-02-19 18:07:02 +0200 | [diff] [blame] | 28 | vars: |
| 29 | public_key: "{{ ssh_dir }}/{{ offline_ssh_key_file_name }}.pub" |