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

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