---

- include: ../functions/get_secret.yml
  with_items:
   - { path: "{{ basedir }}/influxdb_password",            length: 12 }
   - { path: "{{ basedir }}/influxdb_token",               length: 32 }


- name: "create folder struct for {{ basedir }}"
  file: 
    path: "{{ item }}"
    state: "directory"
  with_items:
    - "{{ basedir }}"


- name: "copy config files for {{ basedir }}"
  template:
    src: "{{ item }}"
    dest: "{{ basedir }}/{{ item }}"
  with_items:
    - docker-compose.yml
    - telegraf.conf
  register: config_files


- name: "stop {{ servicename }} docker"
  docker_compose:
    project_src: "{{ basedir }}"
    state: absent
  when: config_files.changed 


- name: "start {{ servicename }} docker"
  docker_compose:
    project_src: "{{ basedir }}"
    state: present
