---
- hosts: "{{ deploy_hosts }}"
  remote_user: ubuntu
  tasks:
    - name: copy shell
      copy:
        src: ../deploy/cleanup.sh
        dest: "{{ deploy_dir }}/cleanup.sh"
        owner: ubuntu
        group: ubuntu
        mode: 0777
    # - name: cleanup previous backup files
    #   shell: cd {{ deploy_dir }} && ./cleanup.sh
    - name: copy execute file to dest
      copy:
        src: ../jx-callback
        dest: "{{ deploy_dir }}/jx-callback"
        owner: ubuntu
        group: ubuntu
        mode: 0755
        backup: no
    - name: copy conf file to dest
      copy:
        src: ../conf/
        dest: "{{ deploy_dir }}/conf/"
        owner: ubuntu
        group: ubuntu
        mode: 0555
    - name: copy swagger files to dest
      copy:
        src: ../swagger
        dest: "{{ deploy_dir }}/"
        owner: ubuntu
        group: ubuntu
        mode: 0555

    - name: shell
      shell: cd {{ deploy_dir }}/conf && sed -i 's/runmode\s*=\s*.*/runmode = {{ runmode }}/' app.conf && sudo systemctl restart jx-callback
      when: runmode == "prod"

    - name: shell
      shell: cd {{ deploy_dir }}/conf && sed -i 's/runmode\s*=\s*.*/runmode = {{ runmode }}/' app.conf && sudo systemctl restart jx-callback-{{ runmode }}
      when: runmode != "prod"
