ansible.builtin.serverless (v2.9.27) — module

Manages a Serverless Framework project

| "added in version" 2.3 of ansible.builtin"

Authors: Ryan Scott Brown (@ryansb)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.9.27

Description

Provides support for managing Serverless Framework (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
  serverless:
    service_path: '{{ project_dir }}'
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Deploy specific functions
  serverless:
    service_path: '{{ project_dir }}'
    functions:
      - my_func_one
      - my_func_two
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Deploy a project, then pull its resource list back into Ansible
  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
  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
    version_added: '2.7'
    version_added_collection: ansible.builtin

stage:
    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 C(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:
    description:
    - AWS region to deploy the service to.
    - This parameter defaults to C(us-east-1).
    type: str

verbose:
    default: false
    description:
    - Shows all stack events during deployment, and display any Stack Output.
    type: bool
    version_added: '2.7'
    version_added_collection: ansible.builtin

functions:
    default: []
    description:
    - A list of specific functions to deploy.
    - If this is not provided, all functions in the service will be deployed.
    type: list

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
    version_added: '2.4'
    version_added_collection: ansible.builtin

Outputs

command:
  description: Full `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