summaryrefslogtreecommitdiffstats
path: root/ansible/setup.yml
blob: ec57297346d0fc16e246ad7597527c259f70684d (plain)
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
---
- hosts: localhost
  gather_facts: false
  tasks:
    - name: "Check and generate key if needed"
      block:
        - stat:
            path: '{{ private_key }}.pub'
          register: p

        - command: ssh-keygen -f {{ private_key }} -t rsa -N ''
          when: not p.stat.exists
  vars:
    private_key: /root/.ssh/offline_ssh_key

- hosts: all
  gather_facts: false
  tasks:
  - name: Setup authorized_keys file
    authorized_key:
      user: root
      state: present
      key: "{{ lookup('file', public_key) }}"
    become: true
  vars:
    public_key: /root/.ssh/offline_ssh_key.pub