---
- hosts: localhost
  strategy: linear
  vars:
    mitogen_version: master
    mitogen_url: https://github.com/dw/mitogen/archive/{{ mitogen_version }}.zip
  tasks:
    - name: Create mitogen plugin dir
      file:
        path: "{{ item }}"
        state: directory
      become: false
      loop:
        - "{{ playbook_dir }}/plugins/mitogen"
        - "{{ playbook_dir }}/dist"

    - name: download mitogen release
      get_url:
        url: "{{ mitogen_url }}"
        dest: "{{ playbook_dir }}/dist/mitogen_{{ mitogen_version }}.zip"
        validate_certs: true

    - name: extract zip
      unarchive:
        src: "{{ playbook_dir }}/dist/mitogen_{{ mitogen_version }}.zip"
        dest: "{{ playbook_dir }}/dist/"

    - name: copy plugin
      synchronize:
        src: "{{ playbook_dir }}/dist/mitogen-{{ mitogen_version }}/"
        dest: "{{ playbook_dir }}/plugins/mitogen"
