From b166d2550e2672e2a55554474438e47f96191e82 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rados=C5=82aw=20Piliszek?= <radoslaw.piliszek@gmail.com>
Date: Mon, 8 Jul 2019 12:31:42 +0200
Subject: [PATCH] Do not require valid migration_interface for controllers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Controllers lacking compute should not be required to provide
valid migration_interface as it is not used there (and prechecks
do not check that either).

Inclusion of libvirt conf section is now conditional on service type.
libvirt conf section has been moved to separate included file to
avoid evaluation of the undefined variable (conditional block did not
prevent it and using 'default' filter may hide future issues).
See https://github.com/ansible/ansible/issues/58835
Additionally this fixes the improper nesting of 'if' blocks for libvirt.

Change-Id: I77af534fbe824cfbe95782ab97838b358c17b928
Closes-Bug: #1835713
Signed-off-by: Radosław Piliszek <radoslaw.piliszek@gmail.com>
---
 .../templates/nova.conf.d/libvirt.conf.j2     | 19 ++++++++++++++++
 ansible/roles/nova/templates/nova.conf.j2     | 22 ++++---------------
 2 files changed, 23 insertions(+), 18 deletions(-)
 create mode 100644 ansible/roles/nova/templates/nova.conf.d/libvirt.conf.j2

diff --git a/ansible/roles/nova/templates/nova.conf.d/libvirt.conf.j2 b/ansible/roles/nova/templates/nova.conf.d/libvirt.conf.j2
new file mode 100644
index 0000000000..f48c63040a
--- /dev/null
+++ b/ansible/roles/nova/templates/nova.conf.d/libvirt.conf.j2
@@ -0,0 +1,19 @@
+[libvirt]
+connection_uri = "qemu+tcp://{{ migration_interface_address }}/system"
+{% if enable_ceph | bool and nova_backend == "rbd" %}
+images_type = rbd
+images_rbd_pool = {{ ceph_nova_pool_name }}
+images_rbd_ceph_conf = /etc/ceph/ceph.conf
+rbd_user = nova
+disk_cachemodes="network=writeback"
+{% if nova_hw_disk_discard != '' %}
+hw_disk_discard = {{ nova_hw_disk_discard }}
+{% endif %}
+{% endif %}
+{% if nova_backend == "rbd" and external_ceph_cephx_enabled | bool %}
+rbd_secret_uuid = {{ rbd_secret_uuid }}
+{% endif %}
+virt_type = {{ nova_compute_virt_type }}
+{% if nova_libvirt_cpu_mode %}
+cpu_mode = {{ nova_libvirt_cpu_mode }}
+{% endif %}
diff --git a/ansible/roles/nova/templates/nova.conf.j2 b/ansible/roles/nova/templates/nova.conf.j2
index 39bb43d9f9..4a6ac8534e 100644
--- a/ansible/roles/nova/templates/nova.conf.j2
+++ b/ansible/roles/nova/templates/nova.conf.j2
@@ -185,27 +185,13 @@ memcache_security_strategy = ENCRYPT
 memcache_secret_key = {{ memcache_secret_key }}
 memcached_servers = {% for host in groups['memcached'] %}{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ memcached_port }}{% if not loop.last %},{% endif %}{% endfor %}
 
+{% if service_name == 'nova-compute' %}
 {% if nova_compute_virt_type in ['kvm', 'qemu'] %}
-[libvirt]
-connection_uri = "qemu+tcp://{{ migration_interface_address }}/system"
-{% if enable_ceph | bool and nova_backend == "rbd" %}
-images_type = rbd
-images_rbd_pool = {{ ceph_nova_pool_name }}
-images_rbd_ceph_conf = /etc/ceph/ceph.conf
-rbd_user = nova
-disk_cachemodes="network=writeback"
-{% if nova_hw_disk_discard != '' %}
-hw_disk_discard = {{ nova_hw_disk_discard }}
+{# must be an include because Ansible 2.8 (and earlier) does not like defined variables referencing undefined variables: migration_interface_address here #}
+{# see https://github.com/ansible/ansible/issues/58835 #}
+{% include 'nova.conf.d/libvirt.conf.j2' %}
 {% endif %}
 {% endif %}
-{% if nova_backend == "rbd" and external_ceph_cephx_enabled | bool %}
-rbd_secret_uuid = {{ rbd_secret_uuid }}
-{% endif %}
-virt_type = {{ nova_compute_virt_type }}
-{% endif %}
-{% if nova_libvirt_cpu_mode %}
-cpu_mode = {{ nova_libvirt_cpu_mode }}
-{% endif %}
 
 {% if nova_compute_virt_type == "vmware" %}
 [vmware]