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

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