since we are not going to reuse the deployment and config part of the playbook we are going to put the whanApp specific tasks into the whanApp.yaml directly

  ▸ inventory/
  ▸ roles/
  ▾ files/
        whanApp.service
  whanApp.yaml

the ci server conveniently serves up the whanApp.tgz via http

the whanApp.yaml playbook looks like this

---
- hosts: nodejsHosts
  become: true
  roles:
    - nodejs

- hosts: WhanApp
  become: true
  tasks:
    - name: stop whanApp
      service: name=whanApp state=stopped
      ignore_errors: true

    - name: clean up any previous deploys
      file: dest=/opt/whanApp state=absent

    - name: create the app folder
      file: dest=/opt/whanApp state=directory

    - name: fetch it from the ci server
      get_url: url=https://ci-server/whanApp/whanApp-1.0.0.tgz dest=/opt/whanApp-1.0.0.tgz

    - name: extract the tar
      shell: tar -xzf /opt/whanApp-1.0.0.tgz -C /opt/whanApp

    - name: create the systemd service file to control the app state
      copy: src=whanApp.service dest=/etc/systemd/system/whanApp.service
      register: systemdupdated

    - name: daemon reload
      shell: systemctl daemon-reload
      when: (systemdupdated | changed)

    - name: restart whanApp
      service: name=whanApp enabled=yes state=restarted

referring to devdocs.io for the details, from the top...

  • service is a module that controls systemd, so stop any previously started instance
  • ignore_errors: true is a way to skip stuff that fails (default behaviour is to stop the playbook)
  • file is a nice general abstraction for mkdir, rm -rf, chmod, chown, touch etc

    • we remove the folder (whacking the previous deploy, if any) and create the folder again
  • get_url is a wget / curl module
  • copy is a copy a file from the files/ folder to the host module
  • register and when is a way to tie up the results of the .service file and the systemctl daemon-reload tasks so that you don't need to reload the daemon if the .service file didn't change
  • service again to restart the app and enable it to start when the vm boots

the whanApp.service file is a general systemd file

[Service]
ExecStart=/usr/bin/node /opt/whanApp/index.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=whanApp

[Install]
WantedBy=multi-user.target

the execution of the playbook stays the same.