docker-compose.yml.j2 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # {{ ansible_managed }}
  2. ---
  3. version: "{{ compose_schema_version | default('3') }}"
  4. services:
  5. {% for container in containers %}
  6. {% if container.active and container.service_name == item %}
  7. {{ container.service_name }}:
  8. image: {{ container.image }}
  9. container_name: {{ container.container_name | default(container.service_name) }}
  10. {% if container.extra_hosts is defined %}
  11. extra_hosts:
  12. {% for host in container.extra_hosts %}
  13. - {{ host }}
  14. {% endfor %}
  15. {% endif %}
  16. {% if container.network_mode is defined %}
  17. network_mode: {{ container.network_mode }}
  18. {% endif %}
  19. {% if container.privileged is defined %}
  20. privileged: {{ container.privileged }}
  21. {% endif %}
  22. {% if container.cap_add is defined %}
  23. cap_add:
  24. {% for cap in container.cap_add %}
  25. - {{ cap }}
  26. {% endfor %}
  27. {% endif %}
  28. {% if container.devices is defined %}
  29. devices:
  30. {% for device in container.devices %}
  31. - {{ device }}
  32. {% endfor %}
  33. {% endif %}
  34. {% if container.volumes is defined %}
  35. volumes:
  36. {% for volume in container.volumes %}
  37. - {{ volume }}
  38. {% endfor %}
  39. {% endif %}
  40. {% if container.labels is defined %}
  41. labels:
  42. {% for label in container.labels %}
  43. - {{ label }}
  44. {% endfor %}
  45. {% endif %}
  46. {% if container.ports is defined %}
  47. ports:
  48. {% for port in container.ports %}
  49. - "{{ port }}"
  50. {% endfor %}
  51. {% endif %}
  52. {% if ( container.environment is defined ) or ( container.include_global_env_vars is defined and container.include_global_env_vars) %}
  53. environment:
  54. {% if container.include_global_env_vars | default(false) %}
  55. {% for global_var in global_env_vars %}
  56. - {{ global_var }}
  57. {% endfor %}
  58. {% endif %}
  59. {% if container.environment is defined %}
  60. {% for env_var in container.environment %}
  61. - {{ env_var }}
  62. {% endfor %}
  63. {% endif %}
  64. {% endif %}
  65. {% if container.depends_on is defined %}
  66. depends_on:
  67. {% for dependent in container.depends_on %}
  68. - {{ dependent }}
  69. {% endfor %}
  70. {% endif %}
  71. {% if container.hostname is defined %}
  72. hostname: {{ container.hostname }}
  73. {% endif %}
  74. {% if container.mem_limit is defined %}
  75. mem_limit: {{ container.mem_limit }}
  76. {% endif %}
  77. {% if container.command is defined %}
  78. command:
  79. {% for command in container.command %}
  80. - {{ command }}
  81. {% endfor %}
  82. {% endif %}
  83. {% if container.security_opt is defined %}
  84. security_opt:
  85. {% for sec_opt in container.security_opt %}
  86. - {{ sec_opt }}
  87. {% endfor %}
  88. {% endif %}
  89. {% if container.sysctl is defined %}
  90. sysctls:
  91. {% for param in container.sysctl %}
  92. - {{ param }}
  93. {% endfor %}
  94. {% endif %}
  95. {% if container.shm_size is defined %}
  96. shm_size: {{ container.shm_size }}
  97. {% endif %}
  98. {% if container.dns is defined %}
  99. dns:
  100. {% for dns_entry in container.dns %}
  101. - {{ dns_entry }}
  102. {% endfor %}
  103. {% endif %}
  104. {% if container.restart is defined %}
  105. restart: {{ container.restart }}
  106. {% endif %}
  107. {% endif %}
  108. {% if container.networks is defined and container.service_name == item %}
  109. networks:
  110. {% for network in container.networks %}
  111. - {{ network }}
  112. {% endfor %}
  113. {% endif %}
  114. {% endfor %}
  115. {% for container in containers %}
  116. {% if container.service_name == item %}
  117. {% if container.networks is defined %}
  118. networks:
  119. {% for network in container.networks %}
  120. {{ network }}:
  121. external: true
  122. {% endfor %}
  123. {% endif %}
  124. {% endif %}
  125. {% endfor %}