Petr OspalĂ˝ | a60b6ea | 2018-12-19 14:46:38 +0100 | [diff] [blame] | 1 | --- |
| 2 | - hosts: localhost |
| 3 | gather_facts: false |
| 4 | tasks: |
| 5 | - name: "Check and generate key if needed" |
| 6 | block: |
| 7 | - stat: |
| 8 | path: '{{ private_key }}.pub' |
| 9 | register: p |
| 10 | |
| 11 | - command: ssh-keygen -f {{ private_key }} -t rsa -N '' |
| 12 | when: not p.stat.exists |
| 13 | vars: |
| 14 | private_key: /root/.ssh/offline_ssh_key |
| 15 | |
| 16 | - hosts: all |
| 17 | gather_facts: false |
| 18 | tasks: |
| 19 | - name: Setup authorized_keys file |
| 20 | authorized_key: |
| 21 | user: root |
| 22 | state: present |
| 23 | key: "{{ lookup('file', public_key) }}" |
| 24 | become: true |
| 25 | vars: |
| 26 | public_key: /root/.ssh/offline_ssh_key.pub |