diff --git a/lib/ansible/modules/cloud/misc/serverless.py b/lib/ansible/modules/cloud/misc/serverless.py index de58b07cd61..5cad422b48f 100644 --- a/lib/ansible/modules/cloud/misc/serverless.py +++ b/lib/ansible/modules/cloud/misc/serverless.py @@ -7,13 +7,11 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type - ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} - -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: serverless short_description: Manages a Serverless Framework project @@ -22,78 +20,86 @@ description: version_added: "2.3" options: state: - choices: ['present', 'absent'] description: - - Goal state of given stage/project - required: false + - Goal state of given stage/project. + type: str + choices: [ absent, present ] default: present serverless_bin_path: description: - The path of a serverless framework binary relative to the 'service_path' eg. node_module/.bin/serverless - required: false + type: path version_added: "2.4" service_path: description: - The path to the root of the Serverless Service to be operated on. + type: path required: true stage: description: - - The name of the serverless framework project stage to deploy to. This uses the serverless framework default "dev". - required: false + - The name of the serverless framework project stage to deploy to. + - This uses the serverless framework default "dev". + type: str functions: description: - - A list of specific functions to deploy. If this is not provided, all functions in the service will be deployed. - required: false + - A list of specific functions to deploy. + - If this is not provided, all functions in the service will be deployed. + type: list default: [] region: description: - - AWS region to deploy the service to - required: false - default: us-east-1 + - AWS region to deploy the service to. + - This parameter defaults to C(us-east-1). + type: str deploy: description: - - 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. - required: false - default: true + - 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 + default: yes force: description: - - Whether or not to force full deployment, equivalent to serverless `--force` option. - required: false - default: false + - Whether or not to force full deployment, equivalent to serverless C(--force) option. + type: bool + default: no version_added: "2.7" verbose: description: - Shows all stack events during deployment, and display any Stack Output. - required: false - default: false + type: bool + default: no version_added: "2.7" notes: - - Currently, the `serverless` command must be in the path of the node executing the task. In the future this may be a flag. -requirements: [ "serverless", "yaml" ] -author: Ryan Scott Brown (@ryansb) + - Currently, the C(serverless) command must be in the path of the node executing the task. + In the future this may be a flag. +requirements: +- serverless +- yaml +author: +- Ryan Scott Brown (@ryansb) ''' -EXAMPLES = """ -# Basic deploy of a service -- serverless: +EXAMPLES = r''' +- name: Basic deploy of a service + serverless: service_path: '{{ project_dir }}' state: present -# Deploy specific functions -- serverless: +- name: 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: +- 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 + # 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 @@ -102,15 +108,15 @@ EXAMPLES = """ 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: +- 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 -""" +''' -RETURN = """ +RETURN = r''' service_name: type: str description: The service name specified in the serverless.yml that was just deployed. @@ -125,10 +131,9 @@ 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 -""" +''' import os -import traceback try: import yaml @@ -147,7 +152,7 @@ def read_serverless_config(module): config = yaml.safe_load(sls_config.read()) return config except IOError as e: - module.fail_json(msg="Could not open serverless.yml in {0}. err: {1}".format(path, str(e)), exception=traceback.format_exc()) + module.fail_json(msg="Could not open serverless.yml in {0}. err: {1}".format(path, str(e))) module.fail_json(msg="Failed to open serverless config at {0}".format( os.path.join(path, 'serverless.yml'))) @@ -167,15 +172,15 @@ def get_service_name(module, stage): def main(): module = AnsibleModule( argument_spec=dict( - service_path=dict(required=True, type='path'), - state=dict(default='present', choices=['present', 'absent'], required=False), - functions=dict(type='list', required=False), - region=dict(default='', required=False), - stage=dict(default='', required=False), - deploy=dict(default=True, type='bool', required=False), - serverless_bin_path=dict(required=False, type='path'), - force=dict(default=False, required=False), - verbose=dict(default=False, required=False) + service_path=dict(type='path', required=True), + state=dict(type='str', default='present', choices=['absent', 'present']), + functions=dict(type='list'), + region=dict(type='str', default=''), + stage=dict(type='str', default=''), + deploy=dict(type='bool', default=True), + serverless_bin_path=dict(type='path'), + force=dict(type='bool', default=False), + verbose=dict(type='bool', default=False), ), ) diff --git a/test/sanity/validate-modules/ignore.txt b/test/sanity/validate-modules/ignore.txt index 62fd15c2b52..a554b514ccb 100644 --- a/test/sanity/validate-modules/ignore.txt +++ b/test/sanity/validate-modules/ignore.txt @@ -178,7 +178,6 @@ lib/ansible/modules/cloud/misc/proxmox_template.py E323 lib/ansible/modules/cloud/misc/rhevm.py E322 lib/ansible/modules/cloud/misc/rhevm.py E324 lib/ansible/modules/cloud/misc/rhevm.py E335 -lib/ansible/modules/cloud/misc/serverless.py E324 lib/ansible/modules/cloud/misc/terraform.py E324 lib/ansible/modules/cloud/misc/virt.py E322 lib/ansible/modules/cloud/misc/virt.py E326