---
  - name: Create exemONE Agent Directory
    ansible.builtin.file:
      path: "{{ EXEM_HOME }}"
      state: directory
      mode: '0755'

  - name: Copy exemONE manager-agent File
    ansible.builtin.copy:
      src: "{{ role_path }}/files/manager"
      dest: "{{ EXEM_HOME }}"

  - name: Create Agent Script [data]
    ansible.builtin.template:
      src: "{{ item }}.j2"
      dest: "{{ EXEM_HOME }}/manager/data/{{ item }}"
      mode: '0740'
    with_items: 
      - autoload_conf

  - name: Create Agnet Script [os_script]
    ansible.builtin.template:
      src: "{{ item }}.j2"
      dest: "{{ EXEM_HOME }}/manager/os_script/{{ item }}"
      mode: '0755'
    with_items: 
      - linux_service_start.sh

  - name: Create Agnet Script [script]
    ansible.builtin.template:
      src: "{{ item }}.j2"
      dest: "{{ EXEM_HOME }}/manager/script/{{ item }}"
      mode: '0755'
    with_items: 
      - binary_start.sh
      - binary_stop.sh

  - name: Create Agnet Script [service]
    ansible.builtin.template:
      src: "{{ item }}.j2"
      dest: "{{ EXEM_HOME }}/manager/service/{{ item }}"
      mode: '0755'
    with_items: 
      - exem-manager-agent
      - exem-manager-agent.service

  - name: Create Agnet Script [start/stop]
    ansible.builtin.template:
      src: "{{ item }}.j2"
      dest: "{{ EXEM_HOME }}/manager/{{ item }}"
      mode: '0755'
    with_items: 
      - start.sh
      - stop.sh

  - name: Copy binary to linux
    ansible.builtin.copy:
      src: "{{ EXEM_HOME }}/manager/os_binary/exem-manager-agent_linux-2.6-x86_64-64"
      dest: "{{ EXEM_HOME }}/manager/bin/exem-manager-agent"
      mode: '0755'
      remote_src: yes

  - name: exem-manager-agent start
    ansible.builtin.shell: |
      {{ EXEM_HOME }}/manager/start.sh
