Populate extra_hosts with all available in pillar hosts records by default
Since there are fqdn records in Openstack service catalog, we need to
resolve these names to ips inside our containers. From my POV would be good
to populate all containers with this mapping, make it by default for
every service in compose.
Also align indents and small refactoring.
Related-PROD: PROD-26540 (PROD:26540)
Change-Id: Idd793ec792de65f00d8a7a5a457b74d1643be752
diff --git a/docker/files/docker-compose.yml b/docker/files/docker-compose.yml
index 1e54db2..df1487c 100644
--- a/docker/files/docker-compose.yml
+++ b/docker/files/docker-compose.yml
@@ -5,44 +5,53 @@
{{ compose.config|yaml(False)|indent(2) }}
{%- endif %}
+{%- set default_extra_hosts_list = [] %}
+{%- for name, host in pillar.get('linux', {}).get('network', {}).get('host', {}).iteritems() %}
+ {%- for hostname in host.names %}
+ {%- do default_extra_hosts_list.append(hostname + ":" + host.address) %}
+ {%- endfor %}
+{%- endfor %}
+
services:
- {%- for name, srv in service.iteritems() %}
- {%- set env_file_set = False %}
+{%- for name, srv in service.iteritems() %}
+ {%- set service_extra_hosts_list = srv.get('extra_hosts', []) %}
+ {%- do srv.update({'extra_hosts': (default_extra_hosts_list + service_extra_hosts_list)|unique|sort}) %}
{{ name }}:
logging:
driver: journald
options:
tag: {% raw %}'docker.{{.Name}}'{% endraw %}
- {%- if 'env_file' in srv.keys() %}{%- set env_file_set = True %}{%- endif %}
{{ srv|yaml(False)|indent(4) }}
- {%- if not env_file_set and compose.environment is defined %}
+ {%- set env_file_set = False %}
+ {%- if 'env_file' in srv.keys() %}{%- set env_file_set = True %}{%- endif %}
+ {%- if not env_file_set and compose.environment is defined %}
env_file: .env
- {%- endif %}
- {%- endfor %}
+ {%- endif %}
+{%- endfor %}
{%- if volume|default({}) %}
volumes:
-{%- for key, value in volume.iteritems() %}
- {%- if value is mapping %}
+ {%- for key, value in volume.iteritems() %}
+ {%- if value is mapping %}
{{ key }}:
{{ value|yaml(False)|indent(4) }}
- {%- else %}
+ {%- else %}
{{ key }}:
- {%- endif %}
-{%- endfor %}
+ {%- endif %}
+ {%- endfor %}
{%- endif %}
{%- if network|default({}) %}
networks:
-{%- for key, value in network.iteritems() %}
- {%- if value is mapping %}
+ {%- for key, value in network.iteritems() %}
+ {%- if value is mapping %}
{{ key }}:
{{ value|yaml(False)|indent(4) }}
- {%- else %}
+ {%- else %}
{{ key }}:
- {%- endif %}
-{%- endfor %}
+ {%- endif %}
+ {%- endfor %}
{%- endif %}
{#-