Repository: ansible/ansible

Issue:
Serverless Module - Support Verbose Mode
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Feature Idea

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
<!--- Please do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" -->
- serverless.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.0.0
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
```
DEFAULT_HOST_LIST(env: ANSIBLE_INVENTORY) = [u'/.../inventory/dev']
```

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
- N/A

##### SUMMARY
<!--- Explain the problem briefly -->

When using Ansible to deploy Serverless projects it would be very helpful to be able to turn on verbose mode (`-v`)

**Reference:** https://serverless.com/framework/docs/providers/aws/cli-reference/deploy/

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
Add `verbose="true"` to `serverless` command and/or piggyback on Ansible verbose mode
```yaml
- name: configure | Run Serverless
  serverless: stage="{{ env }}" region="{{ ec2_region }}" service_path="{{ serverless_service_path }}" verbose="true"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
You would see Serverless verbose logging in the Ansible log
```
Serverless: Packaging service...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
CloudFormation - CREATE_IN_PROGRESS - AWS::CloudFormation::Stack - ***
CloudFormation - CREATE_IN_PROGRESS - AWS::S3::Bucket - ServerlessDeploymentBucket
(removed additional printout)
Serverless: Operation failed!
```
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
Serverless: Packaging service...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
....
Serverless: Operation failed!
```
**Note:** The `....` seen above is Serverless not listing all AWS commands because it's not in verbose mode


Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/misc/serverless.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/misc/serverless.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @ryansb
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/misc/serverless.py b/lib/ansible/modules/cloud/misc/serverless.py
--- a/lib/ansible/modules/cloud/misc/serverless.py
+++ b/lib/ansible/modules/cloud/misc/serverless.py
@@ -56,6 +56,18 @@
         run to send them out. This is mostly useful for generating artifacts to be stored/deployed elsewhere.
     required: false
     default: true
+  force:
+    description:
+      - Whether or not to force full deployment, equivalent to serverless `--force` option.
+    required: false
+    default: false
+    version_added: "2.7"
+  verbose:
+    description:
+      - Shows all stack events during deployment, and display any Stack Output.
+    required: false
+    default: false
+    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" ]
@@ -160,7 +172,9 @@ def main():
             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')
+            serverless_bin_path=dict(required=False, type='path'),
+            force=dict(default=False, required=False),
+            verbose=dict(default=False, required=False)
         ),
     )
 
@@ -173,6 +187,8 @@ def main():
     region = module.params.get('region')
     stage = module.params.get('stage')
     deploy = module.params.get('deploy', True)
+    force = module.params.get('force', False)
+    verbose = module.params.get('verbose', False)
     serverless_bin_path = module.params.get('serverless_bin_path')
 
     if serverless_bin_path is not None:
@@ -187,12 +203,18 @@ def main():
     else:
         module.fail_json(msg="State must either be 'present' or 'absent'. Received: {}".format(state))
 
-    if not deploy and state == 'present':
-        command += '--noDeploy '
+    if state == 'present':
+        if not deploy:
+            command += '--noDeploy '
+        elif force:
+            command += '--force '
+
     if region:
         command += '--region {} '.format(region)
     if stage:
         command += '--stage {} '.format(stage)
+    if verbose:
+        command += '--verbose '
 
     rc, out, err = module.run_command(command, cwd=service_path)
     if rc != 0:


Test patch: