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
This commit is contained in:
Jose Luis Franco Arza 2018-07-23 20:22:47 +02:00
parent f1a1c324fb
commit 44ed2ea4b8
2 changed files with 7 additions and 8 deletions

View File

@ -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

View File

@ -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 %}