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.

This reverts commit 24ff96d08acbbd58bcf408dc8561aea97ad0f3f1.

Related-PROD: PROD-26540 (PROD:26540)

Change-Id: I427381a64d1d5b1685f94ac8d38d2d4df0c5d1ba
diff --git a/docker/files/docker-compose.yml b/docker/files/docker-compose.yml
index 1e54db2..1228fa1 100644
--- a/docker/files/docker-compose.yml
+++ b/docker/files/docker-compose.yml
@@ -5,44 +5,55 @@
   {{ 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 %}
+    {%- if hostname != "localhost" %}
+      {%- do default_extra_hosts_list.append(hostname + ":" + host.address) %}
+    {%- endif %}
+  {%- 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 %}
 
 {#-