{{ ansible_managed | comment }} --- services: {% for container in containers %} {% if container.active %} {{ container.service_name }}:{% if container.anchor is defined %} &{{ container.anchor }}{% endif %} {% if container.fragment is defined %} <<: *{{ container.fragment }} {% else %} image: {{ container.image }} {% endif %} container_name: {{ container.container_name | default(container.service_name) }} {% if container.extra_hosts is defined %} extra_hosts: {% for host in container.extra_hosts %} - {{ host }} {% endfor %} {% endif %} {% if container.network_mode is defined %} network_mode: {{ container.network_mode }} {% endif %} {% if container.networks is defined %} networks: {% if container.networks is iterable and (container.networks is not string and container.networks is not mapping) %} {% for network in container.networks %} - {{ network }} {% endfor %} {% else %} {% for network, params in container.networks.items() %} {{ network }}: {% if params.aliases is defined %} aliases: {% for alias in params.aliases %} - {{ alias }} {% endfor %} {% endif %} {% endfor %} {% endif %} {% endif %} {% if container.build is defined %} build: {{ container.build }} {% endif %} {% if container.user is defined %} user: {{ container.user }} {% endif %} {% if container.privileged is defined %} privileged: {{ container.privileged }} {% endif %} {% if container.cap_add is defined %} cap_add: {% for cap in container.cap_add %} - {{ cap }} {% endfor %} {% endif %} {% if container.group_add is defined %} group_add: {% for group in container.group_add %} - {{ group }} {% endfor %} {% endif %} {% if container.devices is defined %} devices: {% for device in container.devices %} - {{ device }} {% endfor %} {% endif %} {% if container.volumes is defined %} volumes: {% for volume in container.volumes %} - {{ volume }} {% endfor %} {% endif %} {% if container.labels is defined %} {% if container.labels is none %} labels: [] {% else %} labels: {% for label in container.labels %} - {{ label }} {% endfor %} {% endif %} {% endif %} {% if container.ports is defined %} {% if container.ports is none %} ports: [] {% else %} ports: {% for port in container.ports %} - {{ port }} {% endfor %} {% endif %} {% endif %} {% if container.expose is defined %} expose: {% for expose_port in container.expose %} - {{ expose_port }} {% endfor %} {% endif %} {% if ( container.environment is defined ) or ( container.include_global_env_vars is defined and container.include_global_env_vars) %} environment: {% if container.include_global_env_vars | default(false) %} {% for global_var in global_env_vars %} - {{ global_var }} {% endfor %} {% endif %} {% if container.environment is defined %} {% for env_var in container.environment %} - {{ env_var }} {% endfor %} {% endif %} {% endif %} {% if container.depends_on is defined %} depends_on: {% for dependent in container.depends_on %} {% if dependent is mapping %} {{ dependent.service}}: condition: {{ dependent.condition }} {% else %} - {{ dependent }} {% endif %} {% endfor %} {% endif %} {% if container.hostname is defined %} hostname: {{ container.hostname }} {% endif %} {% if container.mem_limit is defined %} mem_limit: {{ container.mem_limit }} {% endif %} {% if container.command is defined %} {% if container.command is string %} command: {{ container.command }} {% else %} command: {% for command in container.command %} - {{ command }} {% endfor %} {% endif %} {% endif %} {% if container.security_opt is defined %} security_opt: {% for sec_opt in container.security_opt %} - {{ sec_opt }} {% endfor %} {% endif %} {% if container.sysctl is defined %} sysctls: {% for param in container.sysctl %} - {{ param }} {% endfor %} {% endif %} {% if container.shm_size is defined %} shm_size: {{ container.shm_size }} {% endif %} {% if container.ulimits is defined %} ulimits: {% if container.ulimits.nproc is defined %} nproc: {{ container.ulimits.nproc }} {% endif %} {% if container.ulimits.nofile is defined %} nofile: {% for param, value in container.ulimits.nofile.items() %} {{ param }}: {{ value }} {% endfor %} {% endif %} {% if container.ulimits.memlock is defined %} memlock: {% for param, value in container.ulimits.memlock.items() %} {{ param }}: {{ value }} {% endfor %} {% endif %} {% endif %} {% if container.tmpfs is defined %} tmpfs: {% for item in container.tmpfs %} - {{ item }} {% endfor %} {% endif %} {% if container.dns is defined %} dns: {% for dns_entry in container.dns %} - {{ dns_entry }} {% endfor %} {% endif %} {% if container.logging.driver is defined %} logging: driver: {{ container.logging.driver }} {% if container.logging.options is defined %} options: {% for option in container.logging.options %} {{ option }}: {{ container.logging.options[option] }} {% endfor %} {% endif %} {% endif %} {% if container.env_file is defined %} env_file: {% for envfile in container.env_file %} - {{ envfile }} {% endfor %} {% endif %} {% if container.healthcheck is defined %} healthcheck: test: {{ container.healthcheck.test }} {% if container.healthcheck.interval is defined %} interval: {{ container.healthcheck.interval }} {% endif %} {% if container.healthcheck.timeout is defined %} timeout: {{ container.healthcheck.timeout }} {% endif %} {% if container.healthcheck.retries is defined %} retries: {{ container.healthcheck.retries }} {% endif %} {% if container.healthcheck.start_period is defined %} start_period: {{ container.healthcheck.start_period }} {% endif %} {% endif %} {% if container.deploy.resources.reservations.devices is defined %} deploy: resources: reservations: devices: - driver: nvidia count: {{ container.deploy.resources.reservations.devices.driver.count | default("1") }} capabilities: [gpu] {% endif %} {% if container.restart is defined %} restart: {{ container.restart }} {% endif %} {% if container.stop_grace_period is defined %} stop_grace_period: {{ container.stop_grace_period }} {% endif %} {% endif %} {% endfor %} {% if docker_networks is defined %} networks: {% for network in docker_networks %} {% if network.active %} {{ network.network_name }}: {% if network.external is defined %} external: {{ network.external }} {% endif %} {% if network.driver is defined %} driver: {{ network.driver }} {% endif %} {% endif %} {% endfor %} {% endif %}