0

I'm trying a to test if ansible is able to run the pm2 module on my local machine.

I installed pm2 for ansible by using:

sudo -H pip install ansible-modules-pm2

And this what my playbook looks like:

---
- hosts: localhost
  connection: local
  become: true
  tasks:
     - name: Install pm2 package using npm
       npm:
           name: pm2
           global: yes

     - name: Start server.js
       pm2:
           name: server
           script: /home/majeed/host_share/server.js
           state: started

When I run the playbook, I get the error:

fatal: [localhost]: FAILED! => {"msg": "Could not find imported module support code for pm2. Looked for either pm2.py or module_utils.py"}

I've checked if pm2 has been installed using:

npm list -g | grep pm2

And it has been installed, there is no issue. pip has also installed ansible-modules-pm2 successfully.

What is causing my playbook to fail ?

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
  • A basic check your should make: run `pip --version` and `ansible --version`. Make sure they both run with the same python version. If not, install either ansible-modules-pm2 or ansible itself in the correct python version so that they both see each other. – Zeitounator Oct 07 '22 at 11:17
  • @Zeitounator Ansible python version = 3.8.10 and pip python version = 3.8, will this cause problem ? – Abdul Majeed Oct 07 '22 at 13:04
  • If they are both 3.8.10 and pointing to the same */lib/pythonXXX/ directories, it's not the cause of your problem. – Zeitounator Oct 08 '22 at 07:07

0 Answers0