---

# Ansible 2.2 pull flag in docker_service still doesn't work as expected if
# any version of the image isn't present on the host
# https://github.com/ansible/ansible/issues/20458
- name: pull logspout image
  docker_image:
    name: gliderlabs/logspout:latest
  tags: logspout-syslog

- name: pull socat image
  docker_image:
    name: alpine/socat:latest
  tags: logspout-syslog

# Run a logspout container to capture all docker logs and stream to a syslog
# endpoint. Use a socat replay container to redirect the UDP stream
# to the host's syslog
# To view the docker logs, you have 3 options
# 1) docker logs <continer_name> (this still works)
# 2) cat /var/log/syslog | grep <container_name>
# 3) stream the logs in real time at: curl http://127.0.0.1:8000/logs
- name: run logspout-syslog
  docker_service:
    project_name: logspout-syslog
    definition:
      version: '2'
      services:
        logspout:
          image: gliderlabs/logspout:latest
          restart: unless-stopped
          volumes:
            - /var/run/docker.sock:/var/run/docker.sock
          ports:
            - "8000:80"
          environment:
              - BACKLOG=false
          command: "syslog://syslog-pipe:514"
        syslog-pipe:
          image: alpine/socat:latest
          restart: unless-stopped
          volumes:
            - /dev/log:/dev/log
          command: "UDP4-LISTEN:514,fork UNIX-CLIENT:/dev/log"
    pull: yes
    state: present
  tags: logspout-syslog
