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

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