summaryrefslogtreecommitdiffstats
path: root/ansible/roles/setup/tasks/main.yml
blob: 5ffcbab9d2344a79d457bfe6f735128ab0d0d556 (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
27
28
29
30
---
- name: "Check and generate key if needed"
  block:
    - name: ssh dir
      file:
        path: "{{ ssh_dir }}"
        state: directory
        mode: 0700

    - name: check ssh pub key exists
      stat:
        path: '{{ private_key }}.pub'
      register: p

    - name: generate ssh keys
      command: ssh-keygen -f {{ private_key }} -t rsa -N ''
      when: not p.stat.exists
  vars:
    private_key: "{{ ssh_dir }}/{{ offline_ssh_key_file_name }}"
  delegate_to: localhost
  run_once: true

- name: Setup authorized_keys file
  authorized_key:
    user: root
    state: present
    key: "{{ lookup('file', public_key) }}"
  become: true
  vars:
    public_key: "{{ ssh_dir }}/{{ offline_ssh_key_file_name }}.pub"