- name: Install python
  apt: pkg=python
- name: Install development headers for python
  apt: pkg=python-dev
- name: Install build-essential
  apt: pkg=build-essential
- name: Install libxslt1-dev
  apt: pkg=libxslt1-dev
- name: Install pip (required to install mitmproxy)
  apt: pkg=python-pip
- name: Install version 0.12 of mitmproxy
  pip:
    name: mitmproxy
    version: 0.12

# Newer version of docker-py causes issues. See
# https://github.com/ansible/ansible-modules-core/issues/1227
- name: Install requirement for ansible docker
  pip:
    name: docker-py
    version: 1.1.0

- name: Install docker container for mitmdump
  docker:
    name: mitmdump
    image: openaustralia/morph-mitmdump
    state: started
    restart_policy: always
    ports: ["8081:8080"]
    env:
      MORPH_URL: "{{ morph_url }}"
      MITMPROXY_SECRET: "{{ mitmproxy_secret }}"

- name: Install python
  apt: pkg=python
- name: Install development headers for python
  apt: pkg=python-dev
- name: Install build-essential
  apt: pkg=build-essential
- name: Install libxslt1-dev
  apt: pkg=libxslt1-dev
- name: Install pip (required to install mitmproxy)
  apt: pkg=python-pip
- name: Install version 0.12 of mitmproxy
  pip:
    name: mitmproxy
    version: 0.12

# Newer version of docker-py causes issues. See
# https://github.com/ansible/ansible-modules-core/issues/1227
- name: Install requirement for ansible docker
  pip:
    name: docker-py
    version: 1.1.0

- name: Install docker container for mitmdump
  docker:
    name: mitmdump
    image: openaustralia/morph-mitmdump
    state: started
    command: mitmdump -p 8081 --quiet --transparent --script /mitmproxy/log_to_morph.py --cadir /mitmproxy
    restart_policy: always
    # We attach the networking of this container to the host. This is necessary
    # because otherwise traffic would get redirected to the container, would
    # get proxied and a new request would come from this container which would
    # promptly get redirected back to the container in a painful infinite loop
    net: host
    env:
      MORPH_URL: "{{ morph_url }}"
      MITMPROXY_SECRET: "{{ mitmproxy_secret }}"

Fix infinite loop issue by using net host on mitmdump container
Fix infinite loop issue by using net host on mitmdump container
