Repository: ansible/ansible-modules-core

Issue:
cloudformation  zero length field name in format when creating a stack
<!--- Verify first that your issue/request is not already reported in GitHub -->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report


##### COMPONENT NAME
<!--- Name of the plugin/module/task -->
cloudformation
##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
2.3.0
```

##### CONFIGURATION
<!---

-->

##### OS / ENVIRONMENT
<!---
Ansible running on Centos 6.6
python 2.6.6
boto (2.43.0)
boto3 (1.4.1)
botocore (1.4.65)
-->

##### SUMMARY
<!--- Explain the problem briefly -->
When running the Cloudformation module, the tasks says it fails with "ValueError: zero length field name in format". However, the stack does get created correctly.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```
---
- name: Launch Base VPC
  cloudformation:
    stack_name: "{{ vpc_stack_name }}" # Test-VPC
    state: "present"
    region: "{{ vpc_region }}
    template: "files/VPC.yml"
    template_parameters:
      ClassC: "{{ vpc_classc }}"
    tags:
      BuiltWith: "Ansible"

```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Cloudformation stack gets built and the tasks returns with changed or OK
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
Stack gets created, but the tasks fails blocking further tasks from being ran.
<!--- Paste verbatim command output between quotes below -->
```
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "/tmp/ansible_n9rFoj/ansible_module_cloudformation.py:203: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6\n  elif hasattr(err, 'message'):\n/tmp/ansible_n9rFoj/ansible_module_cloudformation.py:204: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6\n  error = err.message + ' ' + str(err) + ' - ' + str(type(err))\nTraceback (most recent call last):\n  File \"/tmp/ansible_n9rFoj/ansible_module_cloudformation.py\", line 479, in <module>\n    main()\n  File \"/tmp/ansible_n9rFoj/ansible_module_cloudformation.py\", line 407, in main\n    result = stack_operation(cfn, stack_params['StackName'], 'CREATE')\n  File \"/tmp/ansible_n9rFoj/ansible_module_cloudformation.py\", line 262, in stack_operation\n    ret = get_stack_events(cfn, stack_name)\n  File \"/tmp/ansible_n9rFoj/ansible_module_cloudformation.py\", line 237, in get_stack_events\n    eventline = 'StackEvent {} {} {}'.format(e['ResourceType'], e['LogicalResourceId'], e['ResourceStatus'])\nValueError: zero length field name in format\n", "module_stdout": "", "msg": "MODULE FAILURE"}

```



Discussion:
<!-- @skapykat: Thanks for filing this bug report! -->

@tedder, @ryansb, ping. This issue is waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->

```
fatal: [localhost]: FAILED! => 
 Formatted JSON Data
 {  
  "changed":false,
  "failed":true,
  "module_stderr":"/tmp/ansible_n9rFoj/ansible_module_cloudformation.py:203: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
 elif hasattr(err, 'message'):
/tmp/ansible_n9rFoj/ansible_module_cloudformation.py:204: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
 error = err.message + ' ' + str(err) + ' - ' + str(type(err))
Traceback (most recent call last):
 File \"/tmp/ansible_n9rFoj/ansible_module_cloudformation.py\", line 479, in <module>
   main()
 File \"/tmp/ansible_n9rFoj/ansible_module_cloudformation.py\", line 407, in main
result = stack_operation(cfn, stack_params['StackName'], 'CREATE')
 File \"/tmp/ansible_n9rFoj/ansible_module_cloudformation.py\", line 262, in stack_operation
   ret = get_stack_events(cfn, stack_name)
 File \"/tmp/ansible_n9rFoj/ansible_module_cloudformation.py\", line 237, in get_stack_events
   eventline = 'StackEvent {} {} {}'.format(e['ResourceType'], e['LogicalResourceId'], e['ResourceStatus'])
   ValueError: zero length field name in format",
  "module_stdout":"",
  "msg":"MODULE FAILURE"
 }
```

Reformatting error for my sanity.


Resolving patch:
diff --git a/cloud/amazon/cloudformation.py b/cloud/amazon/cloudformation.py
--- a/cloud/amazon/cloudformation.py
+++ b/cloud/amazon/cloudformation.py
@@ -257,11 +257,11 @@ def get_stack_events(cfn, stack_name):
         return ret
 
     for e in events.get('StackEvents', []):
-        eventline = 'StackEvent {} {} {}'.format(e['ResourceType'], e['LogicalResourceId'], e['ResourceStatus'])
+        eventline = 'StackEvent {ResourceType} {LogicalResourceId} {ResourceStatus}'.format(**e)
         ret['events'].append(eventline)
 
         if e['ResourceStatus'].endswith('FAILED'):
-            failline = '{} {} {}: {}'.format(e['ResourceType'], e['LogicalResourceId'], e['ResourceStatus'], e['ResourceStatusReason'])
+            failline = '{ResourceType} {LogicalResourceId} {ResourceStatus}: {ResourceStatusReason}'.format(**e)
             ret['log'].append(failline)
 
     return ret


Test patch: