Blob Blame History Raw
diff --git a/tasks/ssh.yml b/tasks/ssh.yml
index 1a4e858..b05d01a 100644
--- a/tasks/ssh.yml
+++ b/tasks/ssh.yml
@@ -18,3 +18,15 @@
     key: "{{ keydata.content|b64decode }}"
     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: Add the servers public key to known_hosts on managed node
+  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 1da99df..d12e884 100644
--- a/tests/tests_ssh.yml
+++ b/tests/tests_ssh.yml
@@ -5,6 +5,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 }}
@@ -25,8 +30,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 }}"