Ansible role to deploy a Node.js app to Plesk
Use ansible-nvm role to ensure node is installed.
(passed as extra variables):
project
: Node project name
(passed as extra variables):
exclude
: Additional pattern to exclude from sync, eg.uploads/
.loaddata
: Specify mongo dump directory in host directory to perform a mongo restore, eg.dump
.
(better to keep in configuration file as shown in examples):
conf
: A dictionary to help organize variables, containing:conf.dev_path
: The local path of the project, eg ~/workspace/python/myproject.conf.host_path
: The remote path, where the wsgi index script lies, eg /var/www/vhosts/subscription/domain.
conf.node_version
: The node.js version of the app, default:4.4.7
.conf.node_port
: The node.js server port, default:3000
.conf.start_script
: The node.js start script, default:bin/www
.conf.node_env
: The node.js environment, default:production
.conf.https_only
: If true then configure Apache only for SSL. Default:false
.conf.domain_name
: Domain name to be used in Apache conf. Omit to skip configure Apache in Plesk and register system service.conf.vhost_conf_path
: The remote path, where the apache configuration override (vhost.conf
) is located.
ansible_user_id
: The user id with access to mysql and mysql database.sync_opts
: Additional options for rsync. Default: exclude.*
.
See the folder examples/
:
node_deploy.yml
: playbook examplenode_apps.yml
: configuration example
-
Check that local project path in configuration is valid and has package.json
Checks that there is a valid local path specified in
node_apps.yml
and apackage.json
exists. Avoids deploying wrong files. -
Check if gulp file exists
So that to execute next step.
-
Execute gulp
Execute
gulp --production
locally. -
Create directory
Creates a
project
directory in target to deploy files. -
(Enable Apache proxy) (removed)
Makes sure that
mod_proxy
is enabled. If the configuration changes, causes Apache to restart in the end (notifies handler). -
Build sync options
Append any additional excluded files in the rsync options.
-
Sync files
Syncs files to target directory.
⚠️ Make sure that you have synced back any user uploaded files with manualrsync
. -
Load data
Perform a mongo restore from the optionall specified additional variable
loaddata
. -
Configure Apache
Configure Apache to proxy to server using the provided template file. If the configuration changes, causes Plesk to reconfigure the domain in the end (notifies handler). If the configuration changes, causes Apache to restart in the end (notifies handler).
-
Configure Apache SSL
Same as above, for SSL vhost.
- Set node path
Auxiliary task which sets a variable with the nvm node path executables.
- (Upgrade npm) (removed)
Upgrades global npm.
- (Install npm requirements) (removed)
Run npm install
.
- Configure service
Configure an init service to execute node.js using the provided template file. If the configuration changes, causes service to restart (notifies handler).