---
- name: Create tomcat dirs
  file:
    path: "{{ tomcat_instance_root }}/{{ tomcat_instance_name }}/{{ item }}"
    state: directory
    mode: "u=rwx,g=rwxs,o="
    owner: "{{ tomcat_instance_name }}"
    group: "{{ tomcat_instance_name }}"
  loop:
    - 'conf'
    - 'logs'
    - 'webapps'
    - 'work'
    - 'temp'
    - 'lib'

- name: Templating of env file
  template:
    src: 'templates/env.j2'
    dest: "{{ tomcat_instance_root }}/{{ tomcat_instance_name }}/conf/env"
    mode: "0660"
    owner: "{{ tomcat_instance_name }}"
    group: "{{ tomcat_instance_name }}"
    force: no

- name: Templating of server.xml file
  template:
    src: 'templates/server.xml-tomcat{{ tomcat_version }}.j2'
    dest: "{{ tomcat_instance_root }}/{{ tomcat_instance_name }}/conf/server.xml"
    mode: "0660"
    owner: "{{ tomcat_instance_name }}"
    group: "{{ tomcat_instance_name }}"
    force: no

- name: Copy config file
  copy:
    src: "{{ item }}"
    dest: "{{ tomcat_instance_root }}/{{ tomcat_instance_name }}/conf/{{ item | basename }}"
    mode: "0660"
    owner: "{{ tomcat_instance_name }}"
    group: "{{ tomcat_instance_name }}"
    force: no
  with_fileglob:
    - "tomcat{{ tomcat_version }}/*"
