From 64b09d6eb0734249843bfc4f8fc8058222bf3804 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Thu, 16 Feb 2017 14:29:24 +0000 Subject: [PATCH] Fix bootstrap-servers with invalid api_interface When bootstrapping a host for kolla-ansible the 'kolla-ansible bootstrap-servers' command can fail if for any of the hosts the 'api_interface' is invalid. This happen if the host does not have a network interface matching 'api_interface'. This is possible on a host running bifrost, as bifrost does not require the api_interface variable to be set. This change avoids adding a hosts entry for hosts in the bifrost group that do not have a valid api_interface. It also avoids modifying the hosts file on hosts in the bifrost group that do not have a valid api_interface. Change-Id: Ie111ef54130adf2556ce83c402cdbb5058ace4f6 Closes-bug: #1665364 --- ansible/roles/baremetal/tasks/pre-install.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ansible/roles/baremetal/tasks/pre-install.yml b/ansible/roles/baremetal/tasks/pre-install.yml index bfa277487b..d8632ae4b5 100644 --- a/ansible/roles/baremetal/tasks/pre-install.yml +++ b/ansible/roles/baremetal/tasks/pre-install.yml @@ -21,11 +21,18 @@ dest: /etc/hosts marker: "# {mark} ANSIBLE GENERATED HOSTS" block: | - {% for host in groups['all'] %} - {{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} + {% for host in groups['baremetal'] %} + {% set api_interface = hostvars[host]['api_interface'] %} + {% if host not in groups['bifrost'] or 'ansible_' + api_interface in hostvars[host] %} + {{ hostvars[host]['ansible_' + api_interface]['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} + {% endif %} {% endfor %} become: True - when: customize_etc_hosts | bool + when: + - customize_etc_hosts | bool + # Skip hosts in the bifrost group that do not have a valid api_interface. + - inventory_hostname not in groups['bifrost'] or + 'ansible_' + hostvars[inventory_hostname]['api_interface'] in hostvars[inventory_hostname] - name: Ensure sudo group is present group: name=sudo state=present