---
- name: configure supermaster for docker swarm 
  become: yes
  hosts: supermaster
  vars_files:
    - "var/hosts.yml"
  tasks:

    - name: installing lets encrypt
      apt:
        name: "{{item}}"
        state: latest
        update_cache: yes
      with_items:
        - letsencrypt
        - python3-certbot-nginx

    - name: init swarm
      become: dockerman
      shell: docker swarm init --advertise-addr {{ item.local }}:2377
      with_items:
        - "{{ supermaster }}"
      register: swarm_init
      ignore_errors: yes


    - name: install nfs server
      apt: name=nfs-kernel-server state=present update_cache=yes

    - name: create nfs directory
      file: path=/volume state=directory mode=0777 owner=root group=root

    - name: create multiple directories
      shell: |
        mkdir -p /volume/mongo
        mkdir -p /volume/pg
        mkdir -p /volume/rabbit
        mkdir -p /volume/redis
        mkdir -p /volume/ig/ls/wwwroot
        mkdir -p /volume/ig/api/storage
        mkdir -p /volume/dns
        mkdir -p /volume/nginx
        mkdir -p /volume/portainer
        mkdir -p /volume/mongo/primary
        mkdir -p /data/warehouse/windows
        mkdir -p /var/log/nginx/ig/
        chown -R 1001:1001 /volume/mongo/primary
        chown -R 1001:1001 /volume/pg
        chown -R 1001:1001 /volume/redis
        chown -R 1001:1001 /volume/rabbit
        chmod -R 755 /data/warehouse/windows


        

    - name: create nfs export
      shell: |
        echo "/volume {{item.local}}/32(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports
      with_items:
        - "{{ clients }}"

    - name: exportfs
      shell: exportfs -a


    - name: create overlay network
      shell: |
        docker network create --driver=overlay --attachable mother
      ignore_errors: yes


      

      