Ansible pm2 module failing to return the correct execution status

We have faced an issue on using that the Ansible pm2 module failing to return the correct execution status.

The playbook that used is sharing below.

- name: Start APP
  register: npm_finished
  command: pm2 start server.js --name APP-NAME chdir=APP-FOLDER

Here Ansible hangs when it reaches pm2 start even though the command has been executed on the server as its taking some to complete the process.

To avoid this issue we can use the asynchronous mode to run the tasks at once and then poll until they are done.

Reference: http://techies-world.com/ansible-error-async-task-did-not-complete-within-the-requested-time/

So here we need to modify the playbook as follows.

- name: Start APP
  register: npm_finished
  command: pm2 start server.js --name APP-NAME chdir=APP-FOLDER
  ignore_errors: yes
  async: 1
  poll: 0

Where APP-NAME, APP-FOLDER need to be replaced with the name of the application and the full path to application folder respectively.

That's all…

Leave a Reply