Use the npm ansible module instead of commands

Only run npm build steps if install steps have changed

Change-Id: Ib8aee3904b62b85269dc3225418acad96d178aab
diff --git a/tasks/main.yml b/tasks/main.yml
index fc4d7ca..73e55e5 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,6 +1,5 @@
 ---
 # timesheets tasks/main.yml
-#
 # SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
 # SPDX-License-Identifier: Apache-2.0
 
@@ -46,16 +45,16 @@
 - name: Install timesheetsdb
   become: true
   become_user: "{{ timesheets_username }}"
-  command:
-    chdir: "{{ timesheets_dir }}/db"
-    cmd: "npm install"
-    creates: "{{ timesheets_dir }}/db/node_modules"
+  npm:
+    path: "{{ timesheets_dir }}/db"
+  register: install_timesheetsdb
   notify:
     - "restart-timesheetsdb"
 
 - name: Build timesheetsdb
   become: true
   become_user: "{{ timesheets_username }}"
+  when: install_timesheetsdb.changed  # noqa 503
   command:
     chdir: "{{ timesheets_dir }}/db"
     cmd: "npm run build"
@@ -82,14 +81,14 @@
 - name: Install timesheetsui
   become: true
   become_user: "{{ timesheets_username }}"
-  command:
-    chdir: "{{ timesheets_dir }}/ui"
-    cmd: "npm install"
-    creates: "{{ timesheets_dir }}/ui/node_modules"
+  npm:
+    path: "{{ timesheets_dir }}/ui"
+  register: install_timesheetsui
 
 - name: Build timesheetsui dist
   become: true
   become_user: "{{ timesheets_username }}"
+  when: install_timesheetsui.changed  # noqa 503
   command:
     chdir: "{{ timesheets_dir }}/ui"
     cmd: "npm run-script ng build --prod"