ansible docker_compose 网络

ansible docker_compose network

我正在尝试执行以下任务:

- docker_compose:
    project_name: traefik
    definition:
      traefik:
        image: "traefik:v2.2"
        container_name: "traefik"
        restart: always
        networks:
          - edge-router
        ports:
          - "80:80"
          - "443:443"
          # The Web UI (enabled by --api.insecure=true)
          - "8080:8080"
        volumes:
          - ./traefik.toml:/etc/traefik/traefik.toml
          - ./letsencrypt:/letsencrypt
          - ./routing:/etc/routing/
          - /var/run/docker.sock:/var/run/docker.sock:ro

在 ansible 中,它向我显示:

Configuration error - The Compose file '/tmp/ansibley0n2s1ya/docker-compose.yml' is invalid because:\nUnsupported config option for traefik: 'networks'"

docker-compose.yaml 文件有效:

services:
  traefik:
    image: "traefik:v2.2"
    container_name: "traefik"
    restart: always
    networks:
      - edge-router
    ports:
      - "80:80"
      - "443:443"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
    volumes:
      - ./traefik.toml:/etc/traefik/traefik.toml
      - ./letsencrypt:/letsencrypt
      - ./routing:/etc/routing/
      - /var/run/docker.sock:/var/run/docker.sock:ro

我应该使用什么来代替 ansible 中的网络选项?

networks 在 compose 版本 2 和 3 中可用。除非明确指定,ansible 的 docker-compose 模块默认为版本 1

更新您的定义以包含 version

- docker_compose:
    project_name: traefik
    definition:
      version: '2'
      traefik:
        image: "traefik:v2.2"
        container_name: "traefik"
        restart: always
        networks:
...