--- - name: Set up the environment for the impress-2020 app hosts: webserver tasks: - name: Create web user group become: yes group: name: web - name: Add current user to web group become: yes user: name: "{{ ansible_user_id }}" group: web append: yes - name: Create the app folder become: yes file: path: /srv/impress-2020 state: directory # Root and the `web` group may read/write this folder. Everyone else # may only read it. group: web mode: "u=rwx,g=rwx,o=rx" - name: Add Nodesource apt key become: yes apt_key: id: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280 url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key - name: Add Node v16 apt repository become: yes apt_repository: repo: deb https://deb.nodesource.com/node_16.x focal main - name: Install Node v16 become: yes apt: update_cache: yes name: nodejs state: present - name: Install Yarn become: yes npm: name: yarn global: yes - name: Install pm2 become: yes npm: name: pm2 global: yes - name: Create pm2 startup script # The current user is going to become the pm2 owner of the app server # process. They'll be able to manage it without `sudo`, including during # normal deploys, and run `pm2 monit` from their shell to see status. become: yes command: "pm2 startup systemd {{ ansible_user_id }} --hp /home/{{ ansible_user_id }}" - name: Create pm2 ecosystem file copy: content: > module.exports = { apps: [ { name: "impress-2020", cwd: "/srv/impress-2020/current", script: "yarn", args: "start", instances: "max", exec_mode: "cluster", } ] } dest: "/srv/impress-2020/ecosystem.config.js" - name: Start pm2 ecosystem (even if the app isn't ready yet) command: chdir: "/srv/impress-2020" cmd: "pm2 start ecosystem.config.js" - name: Save pm2 startup script command: pm2 save - name: Install dependencies for the npm module node-canvas become: yes apt: update_cache: yes name: - build-essential - libcairo2-dev - libpango1.0-dev - libjpeg-dev - libgif-dev - librsvg2-dev