community.general.gunicorn module – Run gunicorn with various settings

Note

This module is part of the community.general collection (version 8.6.7).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.gunicorn.

Synopsis

  • Starts gunicorn with the parameters specified. Common settings for gunicorn configuration are supported. For additional configuration use a config file See https://gunicorn-docs.readthedocs.io/en/latest/settings.html for more options. It’s recommended to always use the chdir option to avoid problems with the location of the app.

Aliases: web_infrastructure.gunicorn

Requirements

The below requirements are needed on the host that executes this module.

  • gunicorn

Parameters

Parameter

Comments

app

aliases: name

string / required

The app module. A name refers to a WSGI callable that should be found in the specified module.

chdir

path

Chdir to specified directory before apps loading.

config

aliases: conf

path

Path to the gunicorn configuration file.

pid

path

A filename to use for the PID file. If not set and not found on the configuration file a tmp pid file will be created to check a successful run of gunicorn.

user

string

Switch worker processes to run as this user.

venv

aliases: virtualenv

path

Path to the virtualenv directory.

worker

string

The type of workers to use. The default class (sync) should handle most “normal” types of workloads.

Choices:

  • "sync"

  • "eventlet"

  • "gevent"

  • "tornado "

  • "gthread"

  • "gaiohttp"

Attributes

Attribute

Support

Description

check_mode

Support: none

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Notes

Note

  • If not specified on config file, a temporary error log will be created on /tmp dir. Please make sure you have write access in /tmp dir. Not needed but will help you to identify any problem with configuration.

Examples

- name: Simple gunicorn run example
  community.general.gunicorn:
    app: 'wsgi'
    chdir: '/workspace/example'

- name: Run gunicorn on a virtualenv
  community.general.gunicorn:
    app: 'wsgi'
    chdir: '/workspace/example'
    venv: '/workspace/example/venv'

- name: Run gunicorn with a config file
  community.general.gunicorn:
    app: 'wsgi'
    chdir: '/workspace/example'
    conf: '/workspace/example/gunicorn.cfg'

- name: Run gunicorn as ansible user with specified pid and config file
  community.general.gunicorn:
    app: 'wsgi'
    chdir: '/workspace/example'
    conf: '/workspace/example/gunicorn.cfg'
    venv: '/workspace/example/venv'
    pid: '/workspace/example/gunicorn.pid'
    user: 'ansible'

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

gunicorn

string

process id of gunicorn

Returned: changed

Sample: "1234"

Authors

  • Alejandro Gomez (@agmezr)