Blob Blame History Raw
diff --git a/tasks/ssh.yml b/tasks/ssh.yml
index 1573e90..172fd5b 100644
--- a/tasks/ssh.yml
+++ b/tasks/ssh.yml
@@ -15,3 +15,15 @@
     key: "{{ keydata.stdout }}"
     state: present
   delegate_to: "{{ kdump_ssh_server }}"
+
+- name: fetch the servers public key
+  slurp:
+    src: /etc/ssh/ssh_host_rsa_key.pub
+  register: serverpubkey
+  delegate_to: "{{ kdump_ssh_server }}"
+
+- name:
+  known_hosts:
+    key:  "{{ kdump_ssh_server_location }} {{ serverpubkey.content | b64decode }}"
+    name: "{{ kdump_ssh_server_location }}"
+    path: /etc/ssh/ssh_known_hosts
diff --git a/templates/kdump.conf.j2 b/templates/kdump.conf.j2
index bf24210..504ff34 100644
--- a/templates/kdump.conf.j2
+++ b/templates/kdump.conf.j2
@@ -1,12 +1,17 @@
 # {{ ansible_managed }}
 
 {% if kdump_target %}
-{{ kdump_target.type }} {{ kdump_target.location }}
-{% endif %}
+{% if kdump_target.type == "ssh" %}
+ssh {{ kdump_target.location | d(kdump_ssh_user ~ '@' ~ kdump_ssh_server) }}
 
-{% if kdump_target and kdump_target.type == "ssh" and kdump_sshkey != '/root/.ssh/kdump_id_rsa' %}
+{% if kdump_sshkey != '/root/.ssh/kdump_id_rsa' %}
 sshkey {{ kdump_sshkey }}
 {% endif %}
+{% else %}
+{{ kdump_target.type }} {{ kdump_target.location  }}
+
+{% endif %}
+{% endif %}
 
 path {{ kdump_path }}
 {% if kdump_core_collector %}
diff --git a/tests/tests_ssh.yml b/tests/tests_ssh.yml
index 679148e..bcd1795 100644
--- a/tests/tests_ssh.yml
+++ b/tests/tests_ssh.yml
@@ -6,6 +6,11 @@
     # known and ansible is supposed to be configured to be able to
     # connect to it (via inventory).
     kdump_ssh_server_outside: localhost
+    kdump_ssh_source: "{{ ansible_env['SSH_CONNECTION'].split()[0] }}"
+
+    # this is the address at which the ssh dump server can be reached
+    # from the managed host. Dumps will be uploaded there.
+    kdump_ssh_server_inside: "{{ kdump_ssh_source if kdump_ssh_source in hostvars[kdump_ssh_server_outside]['ansible_all_ipv4_addresses'] + hostvars[kdump_ssh_server_outside]['ansible_all_ipv6_addresses']  else hostvars[kdump_ssh_server_outside]['ansible_default_ipv4']['address'] }}"
 
   tasks:
     - name: gather facts from {{ kdump_ssh_server_outside }}
@@ -13,6 +18,18 @@
       delegate_to: "{{ kdump_ssh_server_outside }}"
       delegate_facts: True
 
+    - name: debug kdump_ssh_server_inside
+      debug:
+        var: kdump_ssh_server_inside
+
+    - name: debug ansible_ssh_private_key_file
+      debug:
+        var: ansible_ssh_private_key_file
+
+    - name: debug {{ kdump_ssh_server_outside }}
+      debug:
+        msg: "{{ kdump_ssh_server_outside }}: {{ hostvars[kdump_ssh_server_outside]['ansible_host'] |d('') }}, {{ hostvars[kdump_ssh_server_outside]['ansible_ssh_host'] |d('') }}"
+
     - include_role:
         name: kdump
       vars:
@@ -25,8 +42,5 @@
           type: ssh
           # This is the ssh dump server address visible from inside
           # the machine being configured. Dumps are to be copied
-          # there. We make here the assumption that this machine is
-          # being run as a VM and the dump server is the VM host
-          # (i.e. for ansible this is localhost). From the VM its
-          # address is then identical to the default route.
-          location: "{{ kdump_ssh_user }}@{{ ansible_default_ipv4.gateway }}"
+          # there.
+          location: "{{ kdump_ssh_user }}@{{ kdump_ssh_server_inside }}"
diff --git a/vars/main.yml b/vars/main.yml
new file mode 100644
index 0000000..34d2d62
--- /dev/null
+++ b/vars/main.yml
@@ -0,0 +1,2 @@
+# determine the managed node facing ssh server address
+kdump_ssh_server_location: "{{ kdump_target.location | regex_replace('.*@(.*)$', '\\1') if kdump_target.location is defined else kdump_ssh_server }}"