facts: fix bug in grafana_server_addr fact setting

If no grafana-server group is defined while an mgr group is, that task
will fail because `hostvars[groups[grafana_server_group_name][0]` can't
return anything since `groups['grafana-server']` will be a non existing
key.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
pull/4128/head
Guillaume Abrioux 2019-06-24 22:30:23 +02:00
parent 45041f52fd
commit 366b309c12
1 changed files with 4 additions and 2 deletions

View File

@ -305,5 +305,7 @@
- name: set grafana_server_addr fact
set_fact:
grafana_server_addr: "{{ (hostvars[groups[grafana_server_group_name][0] | default(groups[mgr_group_name][0])])['ansible_all_ipv4_addresses'] | ipaddr(public_network) | first }}"
when: groups.get(grafana_server_group_name, []) | length > 0 or groups.get(mgr_group_name, []) | length > 0
grafana_server_addr: "{{ (hostvars[groups[grafana_server_group_name][0] if groups.get(grafana_server_group_name, []) | length > 0 else groups[mgr_group_name][0]])['ansible_all_ipv4_addresses'] | ipaddr(public_network) | first }}"
when:
- (groups.get(grafana_server_group_name, []) | length > 0 or groups.get(mgr_group_name, []) | length > 0)
- dashboard_enabled | bool