monakhos/ansible/roles/ssh/tasks/main.yaml

62 lines
1.6 KiB
YAML
Raw Normal View History

2024-07-10 11:06:57 +02:00
- name: Setup ssh dir
file:
path: "{{ home }}/.ssh"
state: directory
recurse: true
owner: "{{ user }}"
- name: Copy pre-generated ssh keys
when: "not target_is_real"
block:
- copy:
src: ./vm_files/remote_key
dest: "{{ home }}/.ssh/{{ device_name }}_generic_ed25519"
mode: u=rw,g=,o=
2024-07-10 11:06:57 +02:00
- copy:
src: ./vm_files/remote_key.pub
dest: "{{ home }}/.ssh/{{ device_name }}_generic_ed25519.pub"
mode: u=rw,g=,o=
2024-07-10 11:06:57 +02:00
- name: Config git
template:
src: ssh_config
dest: "{{ home }}/.ssh/config"
owner: "{{ user }}"
mode: u=rw,g=,o=
2025-09-22 14:20:35 +02:00
- delegate_to: localhost
ansible.builtin.tempfile:
state: directory
suffix: ssh_known_hosts
register: tempdir_known_hosts
- name: Load known hosts from profiles
2025-09-22 14:20:35 +02:00
delegate_to: localhost
template:
2025-09-22 14:20:35 +02:00
# load from controller host, from the work profile repository
src: "{{ profiles_paths[item.name] }}/configs/ssh/known_hosts"
dest: "{{ tempdir_known_hosts.path }}/{{ item.name }}"
with_items: "{{ enabled_profiles }}"
2025-09-22 14:20:35 +02:00
# - name: Execute a command
# ansible.builtin.command: "sleep infinity"
- name: Concat known hosts
2024-07-10 11:06:57 +02:00
template:
src: ssh/known_hosts
2024-07-10 11:06:57 +02:00
dest: "{{ home }}/.ssh/known_hosts"
vars:
2025-09-22 14:20:35 +02:00
origin_dir: "{{ tempdir_known_hosts.path }}"
2024-07-10 11:06:57 +02:00
2024-08-01 11:29:39 +02:00
- name: Ensure ssh config profiles dir exists
file:
path: "{{ home }}/.ssh/profiles"
state: directory
- name: Load ssh config of profiles
template:
2025-09-22 14:20:35 +02:00
src: "{{ profiles_paths[item.name] }}/configs/ssh/config"
dest: "{{ home }}/.ssh/profiles/{{ item.name }}"
mode: u=rw,g=,o=
with_items: "{{ enabled_profiles }}"