Coder Social home page Coder Social logo

10sr / ansible-modules-pm2 Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 210 KB

Ansible Module to Manage Processes via PM2

Home Page: https://pypi.org/project/ansible-modules-pm2/

License: GNU General Public License v3.0

Makefile 7.06% Python 90.63% Shell 0.69% HTML 1.63%

ansible-modules-pm2's People

Contributors

10sr avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

ansible-modules-pm2's Issues

[enhancement] Can't use env parameter on start by config mode

quick patch below to allow passing [env] parameter to pm2 start by config command.
as it is on : pm2 start ecosystem.config.js --env=production

--- pm2.py.original	2021-06-03 08:01:47.976320573 +0700
+++ pm2.py.with-env	2021-06-03 09:02:29.577615407 +0700

@@ -170,7 +170,11 @@
         if chdir is None:
             target = os.path.abspath(target)
             chdir = os.path.dirname(target)
-        rc, out, err = self._run_pm2(["start", target], check_rc=True, cwd=chdir)
+        if self.module.params['env'] is None:
+            rc, out, err = self._run_pm2(["start", target], check_rc=True, cwd=chdir)
+        else:
+            env = "--env=" + self.module.params['env']
+            rc, out, err = self._run_pm2(["start", target, env], check_rc=True, cwd=chdir)
         self._update_info()
         return {"rc": rc, "stdout": out, "stderr": err}
 
@@ -254,7 +258,7 @@
         return
 
 
-def do_pm2(module, name, config, script, state, chdir, executable):
+def do_pm2(module, name, config, script, state, chdir, executable, env):
     result = {}
     pm2 = _Pm2App(module, name, executable)
 
@@ -352,6 +356,7 @@
             script=dict(type="path"),
             executable=dict(type="path"),
             chdir=dict(type="path"),
+            env=dict(required=False),
         ),
         supports_check_mode=True,
         mutually_exclusive=[["config", "script"]],
@@ -366,6 +371,7 @@
             script=module.params["script"],
             executable=module.params["executable"],
             chdir=module.params["chdir"],
+            env=module.params["env"],
         )
 
     except _TaskFailedException as e:

Can't use module in Ansible 2.9.13

installed module
pip3 install ansible-modules-pm2

Error in pipeline usin Ansible pm2 module:

ERROR! couldn't resolve module/action 'pm2'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/home/ansible/roles/dev/tasks/dev_back.yml': line 22, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:

About ansible (ansible was installed using pip3):

$ ansible --version
ansible 2.9.12
  config file = /home/ansible/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.8 (default, Apr  2 2020, 13:34:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

Real module folder:

$ pwd
/home/ansible

$ ls -lah .local/lib/python3.6/site-packages/ansible/modules/pm2/
total 24K
drwxrwxr-x. 3 ansible ansible 4.0K Sep 10 19:27 .
drwxrwxr-x. 3 ansible ansible 4.0K Sep 10 19:27 ..
-rw-rw-r--. 1 ansible ansible    0 Sep 10 19:27 __init__.py
-rw-rw-r--. 1 ansible ansible  11K Sep 10 19:27 pm2.py
drwxrwxr-x. 2 ansible ansible 4.0K Sep 10 19:27 __pycache__

I could copy module:
# cp -r .local/lib/python3.6/site-packages/ansible/modules/pm2/ /usr/local/lib/python3.6/site-packages/ansible/modules

Task fails with "Unexpected pm2 jlist output"

When starting this process that runs a Linux binary it doesn't seem to have a pid defined in the jlist output. This is causing the code to throw an exception at:

self.pid = self.info_raw["pid"]

This is the process.json:

{
    "apps" : [
        {
            "name": "watermark",
            "exec_interpreter": "none",
            "cwd": "/home/hq-test1/apps/testapp",
            "script": "testappPiDecoder",
            "args": "-ac hw:CARD=LISMIIS8X8192K -C 8 -P 8001",
            "exp_backoff_restart_delay": 100,
            "log_date_format": "YYYY-MM-DD hh:mm:ss",
            "kill_timeout": 3000,
            "vizion": false
        }
    ]
}

This is the jlist output:

[
        {
        "name": "testapp",
        "pm2_env": {
            "filter_env": [],
            "namespace": "default",
            "kill_retry_time": 100,
            "windowsHide": true,
            "username": "root",
            "treekill": true,
            "automation": true,
            "pmx": true,
            "instance_var": "NODE_APP_INSTANCE",
            "autorestart": true,
            "vizion": false,
            "merge_logs": true,
            "kill_timeout": 3000,
            "exp_backoff_restart_delay": 100,
            "env": {
                "PWD": "/home/ubuntu",
                "PM2_JSON_PROCESSING": "true",
                "PM2_USAGE": "CLI",
                "SUDO_GID": "1000",
                "SUDO_UID": "1000",
                "SUDO_USER": "ubuntu",
                "SUDO_COMMAND": "/bin/sh -c echo BECOME-SUCCESS-xhpkosaeedoarokpyictbjislpnxsrlo ; /usr/bin/python3 /home/ubuntu/.ansible/tmp/ansible-tmp-1646275245.5922027-14710-271449905295174/AnsiballZ_pm2.py",
                "SHELL": "/bin/bash",
                "HOME": "/root",
                "USER": "root",
                "LOGNAME": "root",
                "MAIL": "/var/mail/root",
                "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin",
                "TERM": "xterm-256color",
                "LS_COLORS": "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:",
                "LANG": "C.UTF-8",
                "PM2_HOME": "/root/.pm2",
                "testapp": "{}",
                "unique_id": "dbe421fb-819a-4bec-8abb-b96c29f2808a"
            },
            "log_date_format": "YYYY-MM-DD hh:mm:ss",
            "exec_interpreter": "none",
            "args": [
                "-ac",
                "hw:CARD=LISMIIS8X8192K",
                "-C",
                "8",
                "-P",
                "8001"
            ],
            "cwd": "/home/hq-test1/apps/testapp",
            "name": "testapp",
            "node_args": [],
            "pm_exec_path": "/home/hq-test1/apps/testapp/testappPiDecoder",
            "pm_cwd": "/home/hq-test1/apps/testapp",
            "exec_mode": "fork_mode",
            "instances": 1,
            "pm_out_log_path": "/root/.pm2/logs/testapp-out.log",
            "pm_err_log_path": "/root/.pm2/logs/testapp-error.log",
            "pm_pid_path": "/root/.pm2/pids/testapp-9.pid",
            "km_link": true,
            "vizion_running": false,
            "NODE_APP_INSTANCE": 0,
            "PWD": "/home/ubuntu",
            "PM2_JSON_PROCESSING": "true",
            "PM2_USAGE": "CLI",
            "SUDO_GID": "1000",
            "SUDO_UID": "1000",
            "SUDO_USER": "ubuntu",
            "SUDO_COMMAND": "/bin/sh -c echo BECOME-SUCCESS-xhpkosaeedoarokpyictbjislpnxsrlo ; /usr/bin/python3 /home/ubuntu/.ansible/tmp/ansible-tmp-1646275245.5922027-14710-271449905295174/AnsiballZ_pm2.py",
            "SHELL": "/bin/bash",
            "HOME": "/root",
            "USER": "root",
            "LOGNAME": "root",
            "MAIL": "/var/mail/root",
            "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin",
            "TERM": "xterm-256color",
            "LS_COLORS": "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:",
            "LANG": "C.UTF-8",
            "PM2_HOME": "/root/.pm2",
            "testapp": "{}",
            "unique_id": "dbe421fb-819a-4bec-8abb-b96c29f2808a",
            "status": "errored",
            "pm_uptime": 1646275293458,
            "axm_actions": [],
            "axm_monitor": {},
            "axm_options": {},
            "axm_dynamic": {},
            "created_at": 1646275248972,
            "pm_id": 9,
            "restart_time": 71,
            "unstable_restarts": 0,
            "exit_code": 0,
            "prev_restart_delay": 0
        },
        "pm_id": 9,
        "monit": {
            "memory": 0,
            "cpu": 0
        }
    }
]

ERROR! couldn't resolve module/action 'pm2'. This often indicates a misspelling, missing collection, or incorrect module path.

@10sr Getting error on Ansible playbook.

ERROR! couldn't resolve module/action 'pm2'. This often indicates a misspelling, missing collection, or incorrect module path.

Below is my block

   - name: test pm2 
     pm2:
       name: test-back
       state: started
       chdir: /usr/share/nginx/test-back
       executable: /usr/bin/pm2

I tried with python 3.6.8 and 3.8.3. same error.
Ansible version: 2.9.12
OS: RedHat 8.2

I used below command to install this module

pip install ansible-modules-pm2

I am also not able to import pm2 from python shell

>>> import pm2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pm2'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.