Fence options before casting to json

These options could be "undefined" which is an object and not json
serializable. This change ensures if an option is undefined it defaults
to an empty set which will allow the option to be json serialized.

Change-Id: I1a81bafa441aa6400bfbec50d57e56df4d09bda3
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2018-12-20 16:58:25 -06:00
parent eb3bcb8daa
commit 9a896aa81a
2 changed files with 9 additions and 7 deletions

View File

@ -11,7 +11,9 @@
############################# Heartbeat ######################################
{% set icmp_hosts = [] %}
{% for host_item in groups['all'] %}
{% set _ = icmp_hosts.extend([hostvars[host_item]['ansible_host']]) %}
{% if hostvars[host_item]['ansible_host'] is defined %}
{% set _ = icmp_hosts.extend([hostvars[host_item]['ansible_host']]) %}
{% endif %}
{% endfor %}
# Configure monitors
heartbeat.monitors:
@ -28,7 +30,7 @@ heartbeat.monitors:
schedule: '@every 30s' # every 30 seconds from start of beat
# List of hosts to ping
hosts: {{ icmp_hosts | to_json }}
hosts: {{ (icmp_hosts | default([])) | to_json }}
# Configure IP protocol types to ping on if hostnames are configured.
# Ping all resolvable IPs if `mode` is `all`, or only one IP if `mode` is `any`.
ipv4: true
@ -103,7 +105,7 @@ heartbeat.monitors:
# Using `tls`/`ssl`, an SSL connection is established. If no ssl is configured,
# system defaults will be used (not supported on windows).
# If `port` is missing in url, the ports setting is required.
hosts: {{ hosts | to_json }}
hosts: {{ (hosts | default([])) | to_json }}
# Configure IP protocol types to ping on if hostnames are configured.
# Ping all resolvable IPs if `mode` is `all`, or only one IP if `mode` is `any`.
@ -169,7 +171,7 @@ heartbeat.monitors:
schedule: '@every 60s' # every 30 seconds from start of beat
# Configure URLs to ping
urls: {{ hosts | to_json }}
urls: {{ (hosts | default([])) | to_json }}
# Configure IP protocol types to ping on if hostnames are configured.
# Ping all resolvable IPs if `mode` is `all`, or only one IP if `mode` is `any`.

View File

@ -8,7 +8,7 @@ output.elasticsearch:
# Scheme and port can be left out and will be set to the default (http and 9200)
# In case you specify and additional path, the scheme is required: http://localhost:9200/path
# IPv6 addresses should always be defined as: https://[2001:db8::1]:9200
hosts: {{ data_hosts | to_json }}
hosts: {{ (data_hosts | default([])) | to_json }}
# Set gzip compression level.
compression_level: 3
@ -99,7 +99,7 @@ output.logstash:
enabled: true
# The Logstash hosts
hosts: {{ data_hosts | to_json }}
hosts: {{ (data_hosts | default([])) | to_json }}
# Number of workers per Logstash host.
worker: 1
@ -393,7 +393,7 @@ xpack.monitoring.elasticsearch:
# Scheme and port can be left out and will be set to the default (http and 9200)
# In case you specify and additional path, the scheme is required: http://localhost:9200/path
# IPv6 addresses should always be defined as: https://[2001:db8::1]:9200
hosts: {{ data_hosts | to_json }}
hosts: {{ (data_hosts | default([])) | to_json }}
# Set gzip compression level.
compression_level: 9