Repository: ansible/ansible

Issue:
Its impossible use changeset_name parameter in cloudformation module
<!---
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: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
cloudformation

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel 97aaf103e8) last updated 2017/07/31 15:29:18 (GMT +300)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/admin/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/admin/ansible/lib/ansible
  executable location = /home/admin/ansible/bin/ansible
  python version = 2.7.5 (default, Sep 15 2016, 22:37:39) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### 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 -->
Using "changeset_name" parameter results in error:

"msg": "local variable 'changeset_name' referenced before assignment local variable 'changeset_name' referenced before assignment - <type 'exceptions.UnboundLocalError'>"

##### 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 -->
```yaml
- name: Creating/Updating stack
  cloudformation:
    stack_name:   "{{stack_name}}"
    profile:      "{{profile}}"
    region:       "{{region}}"
    state:        "{{stack_state}}"
    template_url: "test-change-set.yaml"
    changeset_name: test1
    create_changeset: true
  register:     "{{stack_name}}"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
change set is created with predefined name
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
Fails with error above
<!--- Paste verbatim command output between quotes below -->
```

```



Discussion:
The fix is simple. I tried to push the fix but I get 403 error. 
How can I contribute the fix to project ?
cc @jsmartin @ryansb @tedder
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Hi- thanks for trying to fix! You'll need to clone the Ansible repo, (optionally but recommended) create a branch, and then create a pull request. Once you push the branch to your repo, Github will show you a button to create the PR. Just reference #27487 in that pull request (by using the # sign and the number 27487). I'll then review the code and we can work through any minor issues.

This is a good tutorial on how to fork/branch/PR: https://yangsu.github.io/pull-request-tutorial/

Feel free to ask here for any help.

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/cloudformation.py b/lib/ansible/modules/cloud/amazon/cloudformation.py
--- a/lib/ansible/modules/cloud/amazon/cloudformation.py
+++ b/lib/ansible/modules/cloud/amazon/cloudformation.py
@@ -333,6 +333,9 @@ def create_changeset(module, stack_params, cfn):
 
             changeset_name = 'Ansible-' + stack_params['StackName'] + '-' + sha1(to_bytes(json_params, errors='surrogate_or_strict')).hexdigest()
             stack_params['ChangeSetName'] = changeset_name
+        else:
+            changeset_name = stack_params['ChangeSetName']
+
         # Determine if this changeset already exists
         pending_changesets = list_changesets(cfn, stack_params['StackName'])
         if changeset_name in pending_changesets:


Test patch: