- hosts: surveytool
  become: yes
  vars_files:
    - vars/main.yml
    - local-vars/local.yml
  tasks:
    - name: Create CLDR dir
      file:
        path: "{{ cldr_path }}"
        state: directory
        owner: "{{ cldr_openliberty_user }}"
        group: "{{ cldr_openliberty_group }}"
        mode: 0775
    - name: Rotate CLDR logs
      blockinfile:
        path: "/etc/logrotate.d/surveytool-logs"
        owner: root
        mode: "0644"
        block: |
          {{ cldr_path }}/cldrmail.log {{ cldr_path }}/exception.log {
            su {{ cldr_openliberty_user }} {{ cldr_openliberty_group }}
            daily
            rotate 14
            compress
            missingok
            notifempty
            dateext
            create
          }
        create: true
    - name: create st/README.md
      template:
        dest: "{{ cldr_st_path }}/README.md"
        src: templates/st-readme.j2
        force: yes # want this to reflect the latest
        owner: "{{ cldr_openliberty_user }}"
        group: "{{ cldr_openliberty_group }}"
        mode: "0644"
    - name: Create cldr.properties
      template:
        dest: "{{ cldr_path }}/cldr.properties"
        src: templates/cldr-properties.j2
        force: no
        owner: "{{ cldr_openliberty_user }}"
        group: "{{ cldr_openliberty_group }}"
        mode: "0644"
      notify: Restart OpenLiberty
    - name: Checkout CLDR trunk
      become: yes
      git:
        repo: https://github.com/unicode-org/cldr.git
        dest: "{{ cldr_trunk_path }}"
        force: no
        update: no
        version: main
        remote: origin
        # this is a deep clone because we will need to keep updating
        # it with history. It does not include LFS as that
        # is not needed for the surveytool.
    - name: Fix CLDR trunk perms
      file:
        path: "{{ cldr_trunk_path }}"
        owner: "{{ cldr_surveytool_user }}"
  handlers:
    - name: Restart OpenLiberty
      service:
        name: "{{ cldr_openliberty_service }}"
        state: restarted
