Blame SOURCES/rhel-system-roles-kdump-pr22.diff

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