docker-compose.yml.j2 3.3 KB

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