--- - name: Deploy service hosts: web vars: service_unit_name: "shrlbe" remote_user_name: "shrlbe" src_path: ~/projects/shrl.be dst_path: /srv/shrl.be/ local_archive: "/tmp/shrl.be.tgz" tasks: - name: Archive archive: path: "{{ src_path }}/*" dest: "{{ local_archive }}" exclude_path: - "{{ src_path }}/deploy" - "{{ src_path }}/.vscode" - "{{ src_path }}/.git" - "{{ src_path }}/shrl.*" format: "gz" remove: no delegate_to: localhost - name: stop service service: name: "{{ service_unit_name }}" state: stopped become: true - name: copy zip copy: src: "{{ local_archive}}" dest: "{{ local_archive}}" remote_src: no - name: Unarchive unarchive: src: "{{ local_archive }}" dest: "{{ dst_path }}" remote_src: yes group: "{{ remote_user_name }}" owner: "{{ remote_user_name }}" mode: 0644 become: true - name: Erase archive local file: path: "{{ local_archive }}" state: absent delegate_to: localhost - name: Erase archive remote file: path: "{{ local_archive }}" state: absent - name: Set correct rights on the destination directory file: path: "{{ dst_path }}" state: directory owner: "{{ remote_user_name }}" group: "{{ remote_user_name }}" mode: 0755 recurse: yes become: true - name: restart service service: name: "{{ service_unit_name }}" state: started become: true