From 6130bc841dd25adf9a1ae26e6f82aef6b33328d8 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Tue, 2 Oct 2018 15:55:47 +0200 Subject: [PATCH] config: look up for monitor_address_block in hostvars `monitor_address_block` should be read from hostvars[host] instead of current node being played. eg: Let's assume we have: ``` [mons] ceph-mon0 monitor_address=192.168.1.10 ceph-mon1 monitor_interface=eth1 ceph-mon2 monitor_address_block=192.168.1.0/24 ``` the ceph.conf generation task will end up with: ``` fatal: [ceph-mon0]: FAILED! => {} MSG: 'ansible.vars.hostvars.HostVarsVars object' has no attribute u'ansible_interface' ``` the reason is that it will assume `monitor_address_block` isn't defined even on ceph-mon2 because looking for `monitor_address_block` instead of `hostvars[host]['monitor_address_block']`, therefore it enters in the condition as default value: ``` {%- else -%} {% set interface = 'ansible_' + (monitor_interface | replace('-', '_')) %} {% if ip_version == 'ipv4' -%} {{ hostvars[host][interface][ip_version]['address'] }} {%- elif ip_version == 'ipv6' -%} [{{ hostvars[host][interface][ip_version][0]['address'] }}] {%- endif %} {%- endif %} ``` `monitor_interface` is set with default value `'interface'` so the `interface` variable is built with 'ansible_' + 'interface'. It makes ansible throwing a confusing message about `'ansible_interface'`. Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1635303 Signed-off-by: Guillaume Abrioux --- roles/ceph-config/templates/ceph.conf.j2 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/ceph-config/templates/ceph.conf.j2 b/roles/ceph-config/templates/ceph.conf.j2 index 090d5fb51..18b7b1539 100644 --- a/roles/ceph-config/templates/ceph.conf.j2 +++ b/roles/ceph-config/templates/ceph.conf.j2 @@ -44,11 +44,11 @@ mon initial members = {% for host in groups[mon_group_name] %} {% if not containerized_deployment and not containerized_deployment_with_kv -%} mon host = {% if nb_mon > 0 %} {% for host in groups[mon_group_name] -%} - {% if monitor_address_block != 'subnet' %} + {% if hostvars[host]['monitor_address_block'] is defined and hostvars[host]['monitor_address_block'] != 'subnet' %} {% if ip_version == 'ipv4' -%} - {{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(monitor_address_block) | first }} + {{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(hostvars[host]['monitor_address_block']) | first }} {%- elif ip_version == 'ipv6' -%} - [{{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(monitor_address_block) | first }}] + [{{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(hostvars[host]['monitor_address_block']) | first }}] {%- endif %} {% elif hostvars[host]['monitor_address'] is defined and hostvars[host]['monitor_address'] != '0.0.0.0' -%} {% if ip_version == 'ipv4' -%} @@ -84,11 +84,11 @@ log file = /dev/null mon cluster log file = /dev/null mon host = {% if nb_mon > 0 %} {% for host in groups[mon_group_name] -%} - {% if monitor_address_block != 'subnet' %} + {% if hostvars[host]['monitor_address_block'] is defined and hostvars[host]['monitor_address_block'] != 'subnet' %} {% if ip_version == 'ipv4' -%} - {{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(monitor_address_block) | first }} + {{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(hostvars[host]['monitor_address_block']) | first }} {%- elif ip_version == 'ipv6' -%} - [{{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(monitor_address_block) | first }}] + [{{ hostvars[host]['ansible_all_' + ip_version + '_addresses'] | ipaddr(hostvars[host]['monitor_address_block']) | first }}] {%- endif %} {% elif hostvars[host]['monitor_address'] is defined and hostvars[host]['monitor_address'] != '0.0.0.0' -%} {% if ip_version == 'ipv4' -%}