{"action":"closed","issue":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/1984","labels_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/1984/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/1984/comments","events_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/1984/events","html_url":"https://github.com/ansible/ansible-modules-core/issues/1984","id":103750252,"number":1984,"title":"ec2_elb_lb: exception thrown when using variable for the load_balancer_port","user":{"login":"tomfotherby","id":140179,"avatar_url":"https://avatars.githubusercontent.com/u/140179?v=3","gravatar_id":"","url":"https://api.github.com/users/tomfotherby","html_url":"https://github.com/tomfotherby","followers_url":"https://api.github.com/users/tomfotherby/followers","following_url":"https://api.github.com/users/tomfotherby/following{/other_user}","gists_url":"https://api.github.com/users/tomfotherby/gists{/gist_id}","starred_url":"https://api.github.com/users/tomfotherby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomfotherby/subscriptions","organizations_url":"https://api.github.com/users/tomfotherby/orgs","repos_url":"https://api.github.com/users/tomfotherby/repos","events_url":"https://api.github.com/users/tomfotherby/events{/privacy}","received_events_url":"https://api.github.com/users/tomfotherby/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-28T16:22:13Z","updated_at":"2015-09-03T15:47:41Z","closed_at":"2015-09-03T15:47:41Z","body":"##### Issue Type: Bug Report\r\n\r\n##### Ansible Version: ansible 1.9.1\r\n\r\n##### Ansible Configuration: not changed.\r\n\r\n##### Environment: Ubuntu 14.04.2 LTS\r\n\r\n##### Summary:\r\n\r\nI'm using the `ec2_elb_lb` module to switch ports on a ELB. It works fine when the `load_balancer_port` is hardcoded (e.g. `load_balancer_port: 80`) but not if it is passed in via a variable - a boto exception is generated.\r\n\r\n##### Steps To Reproduce:\r\n\r\n1. Create a test ELB in AWS. Use whatever defaults amazon gives.\r\n2. Have a IAM user that can modify the ELB\r\n3. Create this file called: `switch_elb.yml` but with your own ELB details in:\r\n\r\n```\r\n---\r\n- hosts: localhost\r\n  connection: local\r\n  gather_facts: false\r\n  tasks:\r\n    - name: Switch ELB Port to newly deployed service\r\n      ec2_elb_lb:\r\n        name: \"<your-elb-name>\"\r\n        aws_access_key: \"<your-key>\"\r\n        aws_secret_key: \"<your-secret>\"\r\n        region: \"us-east-1\"\r\n        state: present\r\n        zones:\r\n          - us-east-1e\r\n          - us-east-1c\r\n        listeners:\r\n          - protocol: http\r\n            load_balancer_port: \"{{ public_port }}\"\r\n            instance_protocol: http\r\n            instance_port: \"{{ port }}\"\r\n        purge_listeners: no\r\n```\r\n\r\n(the important thing is the `load_balancer_port` is a variable)\r\n\r\nTrigger the play once:\r\n`$ansible-playbook --connection=local --extra-vars='{\"port\":11006,\"public_port\":80}' switch_elb.yml`\r\n\r\nTrigger it again but with a new port:\r\n`$ansible-playbook --connection=local --extra-vars='{\"port\":11007,\"public_port\":80}' switch_elb.yml`\r\n\r\n##### Expected Results:\r\n\r\n```\r\nPLAY [localhost] ************************************************************** \r\n\r\nTASK: [Switch ELB Port to newly deployed service] ***************************** \r\nchanged: [localhost]\r\n\r\nPLAY RECAP ******************************************************************** \r\nlocalhost                  : ok=1    changed=1    unreachable=0    failed=0   \r\n```\r\n\r\n##### Actual Results:\r\n\r\n```\r\nPLAY [localhost] ************************************************************** \r\n\r\nTASK: [Switch ELB Port to newly deployed service] ***************************** \r\nfailed: [localhost] => {\"failed\": true, \"parsed\": false}\r\nTraceback (most recent call last):\r\n  File \"/home/tom/.ansible/tmp/ansible-tmp-1440777913.42-88246387281716/ec2_elb_lb\", line 2506, in <module>\r\n    main()\r\n  File \"/home/tom/.ansible/tmp/ansible-tmp-1440777913.42-88246387281716/ec2_elb_lb\", line 693, in main\r\n    elb_man.ensure_ok()\r\n  File \"/home/tom/.ansible/tmp/ansible-tmp-1440777913.42-88246387281716/ec2_elb_lb\", line 296, in ensure_ok\r\n    self._set_elb_listeners()\r\n  File \"/home/tom/.ansible/tmp/ansible-tmp-1440777913.42-88246387281716/ec2_elb_lb\", line 471, in _set_elb_listeners\r\n    self._create_elb_listeners(listeners_to_add)\r\n  File \"/home/tom/.ansible/tmp/ansible-tmp-1440777913.42-88246387281716/ec2_elb_lb\", line 406, in _create_elb_listeners\r\n    complex_listeners=listeners)\r\n  File \"/usr/lib/python2.7/dist-packages/boto/ec2/elb/__init__.py\", line 315, in create_load_balancer_listeners\r\n    return self.get_status('CreateLoadBalancerListeners', params)\r\n  File \"/usr/lib/python2.7/dist-packages/boto/connection.py\", line 1166, in get_status\r\n    raise self.ResponseError(response.status, response.reason, body)\r\nboto.exception.BotoServerError: BotoServerError: 400 Bad Request\r\n<ErrorResponse xmlns=\"http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/\">\r\n  <Error>\r\n    <Type>Sender</Type>\r\n    <Code>DuplicateListener</Code>\r\n    <Message>A listener already exists for supertasker-staging-tomtest with LoadBalancerPort 80, but with a different InstancePort, Protocol, or SSLCertificateId</Message>\r\n  </Error>\r\n  <RequestId>91260edf-4d9e-11e5-8c23-efa94f6e45fe</RequestId>\r\n</ErrorResponse>\r\n\r\nFATAL: all hosts have already failed -- aborting\r\n```\r\n\r\nWhat the exception message says is true, (i.e. \"*A listener already exists for supertasker-staging-tomtest with LoadBalancerPort 80, but with a different InstancePort, Protocol, or SSLCertificateId*\") but what Ansible is supposed to do in that case is remove the listener and add it back with the new `InstancePort`. This is what it does when `load_balancer_port` is hardcoded.\r\n\r\nChange `switch_elb.yml` to use `load_balancer_port: 80` and run the play again, it'll work. Odd!"}}