Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elb_target_group UnboundLocalError: local variable 'new_target_group' referenced before assignment #31378

Closed
jcortejoso opened this issue Oct 5, 2017 · 3 comments · Fixed by #31379
Labels
affects_2.4 This issue/PR affects Ansible v2.4 aws bug This issue/PR relates to a bug. cloud module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community.

Comments

@jcortejoso
Copy link
Contributor

ISSUE TYPE
  • Bug Report
COMPONENT NAME

cloud/amazon/elb_target_group

ANSIBLE VERSION
ansible 2.4.0.0
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
CONFIGURATION

Nothing changed

OS / ENVIRONMENT

Running from docker container with:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
NAME="Ubuntu"
VERSION="16.04.1 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.1 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
SUMMARY

Trying to create an ELB Target group, if the target does not exist the execution fails to me.

STEPS TO REPRODUCE
---
- hosts: localhost
  gather_facts: false
  tasks:
    - name: "Create target group"
      elb_target_group:
        name: "test-elb"
        protocol: http
        port: 8081
        vpc_id: "vpc-8dfff2f4"
        successful_response_codes: "200"
        state: present
        deregistration_delay_timeout: 60
EXPECTED RESULTS

The ELB target goupt is created as expected

ACTUAL RESULTS

Ansible fails with error.

<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1507230053.3-234723047541257/ /root/.ansible/tmp/ansible-tmp-1507230053.3-234723047541257/elb_target_group.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1507230053.3-234723047541257/elb_target_group.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1507230053.3-234723047541257/" > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_lpZ57g/ansible_module_elb_target_group.py", line 673, in <module>
    main()
  File "/tmp/ansible_lpZ57g/ansible_module_elb_target_group.py", line 668, in main
    create_or_update_target_group(connection, module)
  File "/tmp/ansible_lpZ57g/ansible_module_elb_target_group.py", line 563, in create_or_update_target_group
    if new_target_group:
UnboundLocalError: local variable 'new_target_group' referenced before assignment

fatal: [localhost]: FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_lpZ57g/ansible_module_elb_target_group.py\", line 673, in <module>\n    main()\n  File \"/tmp/ansible_lpZ57g/ansible_module_elb_target_group.py\", line 668, in main\n    create_or_update_target_group(connection, module)\n  File \"/tmp/ansible_lpZ57g/ansible_module_elb_target_group.py\", line 563, in create_or_update_target_group\n    if new_target_group:\nUnboundLocalError: local variable 'new_target_group' referenced before assignment\n",
    "module_stdout": "Aqui!\n",
    "msg": "MODULE FAILURE",
    "rc": 0
}
@ansibot
Copy link
Contributor

ansibot commented Oct 5, 2017

cc @wimnat
click here for bot help

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 aws bug_report cloud module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Oct 5, 2017
jcortejoso added a commit to jcortejoso/ansible that referenced this issue Oct 5, 2017
@nitzmahone nitzmahone removed the needs_triage Needs a first human triage before being processed. label Oct 6, 2017
@wimnat
Copy link
Contributor

wimnat commented Oct 6, 2017

That variable is only referenced if the call to modify_target_group_attributes fails. It looks like your target group should of been created but the attribute modification fails. Do you have suitable AWS permissions to allow that to happen?

@jcortejoso
Copy link
Contributor Author

Hi @wimnat, it seems you are right and we have restricted IAM permissions. With correct permissions it works as expected, although is more difficult to trace the missing permissions because the code exits due to variable undefined.

Thanks!

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 aws bug This issue/PR relates to a bug. cloud module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants