From 44ed2ea4b8bb0126c5b4a65e7712000d9b9f4655 Mon Sep 17 00:00:00 2001 From: Jose Luis Franco Arza Date: Mon, 23 Jul 2018 20:22:47 +0200 Subject: [PATCH] Set known hosts when --limit is set. When the option --limit is specified the tasks will run only on those hosts passed in the option (or all except the one passed if patterns are used), for that reason we can't consider that the facts will be available for all hosts inside the 'overcloud' group. This patch appends a new line into the known hosts file with the available 'overcloud' group hosts instead of creating a new ssh_known_hosts file. Change-Id: I8c687c53aa4cff18ac15c332a72fb40ed730e69c Closes-Bug: #1782168 --- roles/tripleo-ssh-known-hosts/tasks/main.yml | 12 +++++++----- .../templates/ssh_known_hosts.j2 | 3 --- 2 files changed, 7 insertions(+), 8 deletions(-) delete mode 100644 roles/tripleo-ssh-known-hosts/templates/ssh_known_hosts.j2 diff --git a/roles/tripleo-ssh-known-hosts/tasks/main.yml b/roles/tripleo-ssh-known-hosts/tasks/main.yml index 69576657f..b4f53197b 100644 --- a/roles/tripleo-ssh-known-hosts/tasks/main.yml +++ b/roles/tripleo-ssh-known-hosts/tasks/main.yml @@ -1,9 +1,11 @@ --- - -- name: Template /etc/ssh/ssh_known_hosts +- name: Add hosts key in /etc/ssh/ssh_known_hosts for live/cold-migration become: true - template: - src: ssh_known_hosts.j2 - dest: /etc/ssh/ssh_known_hosts + lineinfile: + path: /etc/ssh/ssh_known_hosts + line: "{{ ssh_known_hosts[hostvars[item]['ansible_hostname']] + ' ssh-rsa ' + hostvars[item]['ansible_ssh_host_key_rsa_public'] }}" + create: yes + with_items: "{{ groups['overcloud']|intersect(play_hosts) }}" tags: - tripleo_ssh_known_hosts + diff --git a/roles/tripleo-ssh-known-hosts/templates/ssh_known_hosts.j2 b/roles/tripleo-ssh-known-hosts/templates/ssh_known_hosts.j2 deleted file mode 100644 index faacc1c63..000000000 --- a/roles/tripleo-ssh-known-hosts/templates/ssh_known_hosts.j2 +++ /dev/null @@ -1,3 +0,0 @@ -{% for host in groups['overcloud'] %} -{{ ssh_known_hosts[hostvars[host]['ansible_hostname']] + ' ssh-rsa ' + hostvars[host]['ansible_ssh_host_key_rsa_public'] }} -{% endfor %}