https://github.com/10sr/ansible-modules-pm2
Ansible Module to Manage Processes via PM2
https://github.com/10sr/ansible-modules-pm2
Last synced: 11 months ago
JSON representation
Ansible Module to Manage Processes via PM2
- Host: GitHub
- URL: https://github.com/10sr/ansible-modules-pm2
- Owner: 10sr
- License: gpl-3.0
- Created: 2020-03-09T03:00:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-22T22:59:05.000Z (over 5 years ago)
- Last Synced: 2025-07-04T21:05:47.698Z (11 months ago)
- Language: Python
- Homepage: https://pypi.org/project/ansible-modules-pm2/
- Size: 205 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/10sr/ansible-modules-pm2/actions)
[](https://badge.fury.io/py/ansible-modules-pm2)
[](https://pepy.tech/project/ansible-modules-pm2)
[](https://github.com/psf/black)
ansible-modules-pm2
===================
Ansible Module to Manage Processes via [PM2](https://pm2.keymetrics.io/)
- Manage the state of processes via pm2 process manager
- Start/Stop/Restart/Reload/Delete applications
Tested on:
- Host Python: 3.8
- Target host Python: 2.7, 3.5, 3.6, 3.7, 3.8
- Ansible: 2.8.10, 2.9.6 (Should work with older versions)
Installation
------------
Install via pip:
```shell
# Have to be installed in the same environment as ansible.
# For details please see the Troubleshooting section below.
pip install ansible-modules-pm2
```
PM2 package have to be installed to target hosts.
For example, add following to your playbook to install pm2 globally:
```yaml
- npm:
name: pm2
global: yes
```
Usage
=====
Basic usage is similar to `service` or `supervisorctl` module:
specify the name and its state. To start an app, give either `script`
or `config`.
Examples
--------
```yaml
---
- name: Start myapp with process config file, if not running
pm2:
name: myapp
config: /path/to/myapp/myapp.json
state: started
- name: Start myapp.js, if not running
pm2:
name: myapp
script: /path/to/myapp/myapp.js
state: started
- name: Stop process named myapp, if running
pm2:
name: myapp
state: stopped
- name: Restart myapp, in all cases
pm2:
name: myapp
state: restarted
- name: Reload myapp, in all cases
pm2:
name: myapp
state: reloaded
- name: Delete myapp, if exists
pm2:
name: myapp
state: absent
- name: Specify pm2 executable path
pm2:
name: myapp
state: started
config: /path/to/myapp/myapp.json
executable: /path/to/myapp/node_modules/.bin/pm2
- name: Also specify working directory where running pm2 command
pm2:
name: myapp
state: started
config: /path/to/myapp/myapp.json
executable: /path/to/myapp/node_modules/.bin/pm2
chdir: /path/to/working/directory
```
Arguments
---------
| Parameters | Choices | Comments |
|-----------------|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| name (required) | | Name of the application.
Required for all cases to check current status of app |
| state | `started` (default)
`stopped`
`restarted`
`reloaded`
`absent`
`deleted` | `started`/`stopped`/`absent`/`deleted` are idempotent actions that will not run commands unless necessary.
`restarted` will always restart the process.
`reloaded` will always reload.
Note that `restarted` will fail when the process does not exist (action does not start it automatically). |
| config | | Process configuration file, in JSON or YAML format.
Either `config` or `script` is required when `state=started`. |
| script | | Executalbe file to start.
Either `config` or `script` is required when `state=started`. |
| executable | | Path to pm2 executable. |
| chdir | | Change into this directory before running pm2 start command.
When `state=started` and this option is omitted, use the directory where `config` or `script` exists. |
Troubleshooting
===============
ERROR! couldn't resolve module/action 'pm2'
-------------------------------------------
This and ansible modules have to be installed in the same environment.
You can run the following commands to check where these modules were installed:
```
$ python # Start a python interactive shell
Python 3.7.3 (default, Jun 13 2019, 13:22:19)
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ansible
>>> import ansible.modules.pm2
>>> ansible.__path__
['/path/to/your/venv/lib/python3.7/site-packages/ansible']
>>> ansible.modules.pm2.__path__
['/path/to/your/venv/lib/python3.7/site-packages/ansible/modules/pm2']
```
License
=======
This software is licensed under GPLv3. See `LICENSE` for details.