2024-01-02 09:11:53 +01:00
|
|
|
- name: Check if the SSH key for root already exists
|
|
|
|
ansible.builtin.stat:
|
|
|
|
path: "/root/.ssh/id_rsa.pub"
|
|
|
|
register: ssh_key
|
|
|
|
|
|
|
|
- name: Generate a SSH key for root if it does not exist
|
|
|
|
ansible.builtin.openssh_keypair:
|
|
|
|
path: "/root/.ssh/id_rsa"
|
|
|
|
type: rsa
|
|
|
|
size: 4096
|
2024-01-04 00:18:46 +01:00
|
|
|
when: not ssh_key.stat.exists and run_once_user_root is not defined
|
2024-01-02 09:11:53 +01:00
|
|
|
|
|
|
|
- name: Display the public SSH key
|
|
|
|
command: cat /root/.ssh/id_rsa.pub
|
|
|
|
register: public_key
|
2024-01-04 00:18:46 +01:00
|
|
|
when: not ssh_key.stat.exists and run_once_user_root is not defined
|
2024-01-02 09:11:53 +01:00
|
|
|
|
|
|
|
- name: Output the public SSH key
|
|
|
|
debug:
|
|
|
|
msg: "{{ public_key.stdout }}"
|
2024-01-04 00:18:46 +01:00
|
|
|
when: not ssh_key.stat.exists and run_once_user_root is not defined
|
2024-01-02 09:11:53 +01:00
|
|
|
|
2024-01-04 00:18:46 +01:00
|
|
|
- name: run the user_root tasks once
|
2024-01-02 09:11:53 +01:00
|
|
|
set_fact:
|
2024-01-04 00:18:46 +01:00
|
|
|
run_once_user_root: true
|
|
|
|
when: run_once_user_root is not defined
|