serverless - Manages a Serverless Framework project

New in version 2.3.

Synopsis

Requirements

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

  • serverless
  • yaml

Parameters

Parameter Choices/Defaults Comments
deploy Default:
yes
Whether or not to deploy artifacts after building them. When this option is `false` all the functions will be built, but no stack update will be run to send them out. This is mostly useful for generating artifacts to be stored/deployed elsewhere.
force
(added in 2.7)
Default:
no
Whether or not to force full deployment, equivalent to serverless `--force` option.
functions Default:
[]
A list of specific functions to deploy. If this is not provided, all functions in the service will be deployed.
region Default:
us-east-1
AWS region to deploy the service to
serverless_bin_path
(added in 2.4)
The path of a serverless framework binary relative to the 'service_path' eg. node_module/.bin/serverless
service_path
required
The path to the root of the Serverless Service to be operated on.
stage
The name of the serverless framework project stage to deploy to. This uses the serverless framework default "dev".
state
    Choices:
  • present ←
  • absent
Goal state of given stage/project
verbose
(added in 2.7)
Default:
no
Shows all stack events during deployment, and display any Stack Output.

Notes

Note

  • Currently, the serverless command must be in the path of the node executing the task. In the future this may be a flag.

Examples

# Basic deploy of a service
- serverless:
    service_path: '{{ project_dir }}'
    state: present

# Deploy specific functions
- serverless:
    service_path: '{{ project_dir }}'
    functions:
      - my_func_one
      - my_func_two

# deploy a project, then pull its resource list back into Ansible
- serverless:
    stage: dev
    region: us-east-1
    service_path: '{{ project_dir }}'
  register: sls
# The cloudformation stack is always named the same as the full service, so the
# cloudformation_facts module can get a full list of the stack resources, as
# well as stack events and outputs
- cloudformation_facts:
    region: us-east-1
    stack_name: '{{ sls.service_name }}'
    stack_resources: true

# Deploy a project but use a locally installed serverless binary instead of the global serverless binary
- serverless:
    stage: dev
    region: us-east-1
    service_path: '{{ project_dir }}'
    serverless_bin_path: node_modules/.bin/serverless

Return Values

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

Key Returned Description
command
string
always
Full `serverless` command run by this module, in case you want to re-run the command outside the module.

Sample:
serverless deploy --stage production
service_name
string
always
The service name specified in the serverless.yml that was just deployed.

Sample:
my-fancy-service-dev
state
string
always
Whether the stack for the serverless project is present/absent.



Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Maintenance

This module is flagged as community which means that it is maintained by the Ansible Community. See Module Maintenance & Support for more info.

For a list of other modules that are also maintained by the Ansible Community, see here.

Author

  • Ryan Scott Brown (@ryansb)

Hint

If you notice any issues in this documentation you can edit this document to improve it.