diff --git a/tasks/file.yml b/tasks/file.yml new file mode 100644 index 0000000..2b02c9e --- /dev/null +++ b/tasks/file.yml @@ -0,0 +1,10 @@ +--- + +- name: write ssh_known_hosts file + local_action: known_hosts + args: + path: "{{ playbook_dir }}/ssh_known_hosts" + name: "{{ item }}" + key: "{{ item }},{{ hostvars[item].ssh_ip }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }}" + with_items: "{{play_hosts}}" + run_once: true diff --git a/tasks/main.yml b/tasks/main.yml index 7c492c4..583e2c0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -21,6 +21,13 @@ or not ssh_host_key_state == 'configured' - include: save.yml + when: + ssh_host_key_state == 'configured' or + ssh_host_key_state == 'scanned' or + ssh_host_key_state == 'regenerated' or + ssh_host_key_state == 'fetched' + +- include: file.yml when: ssh_host_key_state == 'configured' or ssh_host_key_state == 'scanned' or diff --git a/tasks/save.yml b/tasks/save.yml index bf2badd..353dcaa 100644 --- a/tasks/save.yml +++ b/tasks/save.yml @@ -5,12 +5,3 @@ - name: host_vars file local_action: template src=host_vars.j2 dest=host_vars/{{inventory_hostname}}/ssh_host_key.yml - -- name: write ssh_known_hosts file - local_action: known_hosts - args: - path: "{{ playbook_dir }}/ssh_known_hosts" - name: "{{ item }}" - key: "{{ item }},{{ hostvars[item].ssh_ip }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }}" - with_items: "{{play_hosts}}" - run_once: true