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

- name: create folder for {{ servicename }} data
  file: 
    path: "{{ item }}"
    state: "directory"
    mode: '0777'
  with_items:
    - "{{ basedir }}/data"
    - "{{ basedir }}/cfg"

- name: privatebin config erstellen
  template:
    src: "conf.php"
    dest: "{{ basedir }}/cfg/conf.php"
  register: config

- name: Docker Compose Konfig-Datei erstellen
  template: 
    src: "{{ item }}" 
    dest: "{{ basedir }}/{{ item }}"
  with_items:
    - "docker-compose.yml"
  register: config


- name: stop {{ servicename }} docker
  community.docker.docker_compose_v2:
    project_src: "{{ basedir }}/"
    state: absent
  when: config.changed

- name: start {{ servicename }} docker
  community.docker.docker_compose_v2:
    project_src: "{{ basedir }}/"
    state: present