- name: Deploy to production hosts: all remote_user: root become: true become_user: "{{ username }}" vars: app_dir: "/home/{{ username }}/invoice" nvm_sh_dir: "/home/{{ username }}/.nvm/nvm.sh" tasks: - name: Checkout repo git: repo: "{{ git_repo }}" dest: "{{ app_dir }}" version: main force: true - name: Install deps shell: | . {{ nvm_sh_dir }} npm install args: executable: /bin/bash chdir: "{{ app_dir }}" - name: Build nextjs server shell: | . {{ nvm_sh_dir }} npm run build args: executable: /bin/bash chdir: "{{ app_dir }}" - name: Sync .next/static shell: | rsync -avP {{ app_dir }}/.next/static {{ app_dir }}/.next/standalone/.next/ - name: Sync public dir shell: | rsync -avP {{ app_dir }}/public {{ app_dir }}/.next/standalone/ - name: Start/restart pm2 process shell: | . {{ nvm_sh_dir }} pm2 restart invoice-app || pm2 start server.js --name invoice-app args: executable: /bin/bash chdir: "{{ app_dir }}/.next/standalone"