community.general.serverless (8.5.0) — module

Manages a Serverless Framework project

Authors: Ryan Scott Brown (@ryansb)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Provides support for managing Serverless Framework (U(https://serverless.com/)) project deployments and stacks.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Basic deploy of a service
  community.general.serverless:
    service_path: '{{ project_dir }}'
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Deploy a project, then pull its resource list back into Ansible
  community.general.serverless:
    stage: dev
    region: us-east-1
    service_path: '{{ project_dir }}'
  register: sls
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# The cloudformation stack is always named the same as the full service, so the
# cloudformation_info module can get a full list of the stack resources, as
# well as stack events and outputs
- cloudformation_info:
    region: us-east-1
    stack_name: '{{ sls.service_name }}'
    stack_resources: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Deploy a project using a locally installed serverless binary
  community.general.serverless:
    stage: dev
    region: us-east-1
    service_path: '{{ project_dir }}'
    serverless_bin_path: node_modules/.bin/serverless

Inputs

    
force:
    default: false
    description:
    - Whether or not to force full deployment, equivalent to serverless C(--force) option.
    type: bool

stage:
    default: ''
    description:
    - The name of the serverless framework project stage to deploy to.
    - This uses the serverless framework default "dev".
    type: str

state:
    choices:
    - absent
    - present
    default: present
    description:
    - Goal state of given stage/project.
    type: str

deploy:
    default: true
    description:
    - Whether or not to deploy artifacts after building them.
    - When this option is V(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.
    type: bool

region:
    default: ''
    description:
    - AWS region to deploy the service to.
    - This parameter defaults to V(us-east-1).
    type: str

verbose:
    default: false
    description:
    - Shows all stack events during deployment, and display any Stack Output.
    type: bool

service_path:
    description:
    - The path to the root of the Serverless Service to be operated on.
    required: true
    type: path

serverless_bin_path:
    description:
    - The path of a serverless framework binary relative to the 'service_path' eg. node_module/.bin/serverless
    type: path

Outputs

command:
  description: Full C(serverless) command run by this module, in case you want to
    re-run the command outside the module.
  returned: always
  sample: serverless deploy --stage production
  type: str
service_name:
  description: The service name specified in the serverless.yml that was just deployed.
  returned: always
  sample: my-fancy-service-dev
  type: str
state:
  description: Whether the stack for the serverless project is present/absent.
  returned: always
  type: str