diff --git a/defaults/main.yml b/defaults/main.yml index 0ae38f6..d9f78d1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -4,4 +4,6 @@ ssh_host_key_types: - rsa ssh_ip: "{{ansible_host}}" ssh_host_key_state: configured -ssh_scan_host: "{{inventory_hostname}}" +ssh_scan_host: "{% if ssh_ip is defined %}{{ ssh_ip }}{% else %}{{inventory_hostname}}{% endif %}" + +ssh_update_local_known_hosts_file: true diff --git a/tasks/file.yml b/tasks/local.yml similarity index 87% rename from tasks/file.yml rename to tasks/local.yml index 47ed31c..93f7596 100644 --- a/tasks/file.yml +++ b/tasks/local.yml @@ -1,6 +1,6 @@ --- -- name: write ssh_known_hosts file +- name: write local ssh_known_hosts file local_action: known_hosts args: path: "{{ lookup('env','HOME') }}/.ssh/known_hosts" diff --git a/tasks/main.yml b/tasks/main.yml index 583e2c0..4ba1b44 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,17 +1,17 @@ --- -- include: regenerate.yml +- import_tasks: regenerate.yml when: ssh_host_key_state == 'regenerated' -- include: scan.yml +- import_tasks: scan.yml when: ssh_host_key_state == 'scanned' -- include: setup.yml +- import_tasks: setup.yml when: - ssh_host_key_state == 'configured' - ansible_ssh_host_key_ed25519_public is defined -- include: fetch.yml +- import_tasks: fetch.yml when: - ssh_host_key_state == 'configured' or ssh_host_key_state == 'fetched' or @@ -20,16 +20,17 @@ and not ansible_ssh_host_key_ed25519_public is defined or not ssh_host_key_state == 'configured' -- include: save.yml +- import_tasks: 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 +- import_tasks: local.yml when: - ssh_host_key_state == 'configured' or - ssh_host_key_state == 'scanned' or - ssh_host_key_state == 'regenerated' or - ssh_host_key_state == 'saved' + - ssh_host_key_state == 'configured' or + ssh_host_key_state == 'scanned' or + ssh_host_key_state == 'regenerated' or + ssh_host_key_state == 'saved' + - ssh_update_local_known_hosts_file