---
- name: Write environment configuration file
  template:
    src: env.ini.j2
    dest: "{{ www_base }}/env.ini"
    owner: azuracast
    group: www-data
    mode: 0644
    force: false

- name: Set up environment file
  ini_file:
    dest: "{{ www_base }}/env.ini"
    section: "configuration"
    option: "application_env"
    value: "{{ app_env }}"
    mode: 0644

- name: Set Permissions on Base App Folder
  file:
    path: "{{ app_base }}"
    state: directory
    owner: azuracast
    group: www-data
    mode: 0775

- name: Clear temp directory
  file:
    path: "{{ tmp_base }}"
    state: absent

- name: Create System Folders
  file:
    path: "{{ azuracast_config_sys_directory }}"
    state: directory
    owner: azuracast
    group: www-data
    mode: 0775
  loop:
    - "{{ tmp_base }}"
    - "{{ tmp_base }}/proxies"
    - "{{ app_base }}/stations"
    - "{{ app_base }}/geoip"
    - "{{ app_base }}/dbip"
    - "{{ app_base }}/backups"
    - "{{ app_base }}/servers"
    - "{{ app_base }}/servers/shoutcast2"
    - "{{ app_base }}/servers/icecast2"
    - "{{ app_base }}/servers/stereo_tool"
    - "{{ app_base }}/uploads"
    - "{{ app_base }}/acme/challenges"
  loop_control:
    loop_var: azuracast_config_sys_directory
