{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/7592","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/7592/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/7592/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/7592/events","html_url":"https://github.com/ansible/ansible/issues/7592","id":34587108,"number":7592,"title":"ec2_group Errors when using self referencing groups","user":{"login":"jimbydamonk","id":5437001,"avatar_url":"https://avatars.githubusercontent.com/u/5437001?v=3","gravatar_id":"","url":"https://api.github.com/users/jimbydamonk","html_url":"https://github.com/jimbydamonk","followers_url":"https://api.github.com/users/jimbydamonk/followers","following_url":"https://api.github.com/users/jimbydamonk/following{/other_user}","gists_url":"https://api.github.com/users/jimbydamonk/gists{/gist_id}","starred_url":"https://api.github.com/users/jimbydamonk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimbydamonk/subscriptions","organizations_url":"https://api.github.com/users/jimbydamonk/orgs","repos_url":"https://api.github.com/users/jimbydamonk/repos","events_url":"https://api.github.com/users/jimbydamonk/events{/privacy}","received_events_url":"https://api.github.com/users/jimbydamonk/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/bug_report","name":"bug_report","color":"fbca04"},{"url":"https://api.github.com/repos/ansible/ansible/labels/cloud","name":"cloud","color":"c7def8"},{"url":"https://api.github.com/repos/ansible/ansible/labels/P2","name":"P2","color":"fad8c7"},{"url":"https://api.github.com/repos/ansible/ansible/labels/plugin","name":"plugin","color":"bfe5bf"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-05-29T19:57:07Z","updated_at":"2016-06-20T13:58:37Z","closed_at":"2014-06-04T18:54:02Z","body":"##### Issue Type:\r\n\r\nBug Report\r\n\r\n##### Ansible Version:\r\n\r\nansible 1.6\r\n\r\n##### Environment:\r\n\r\nN/A\r\n\r\n##### Summary:\r\n\r\nThis playbook:\r\n```\r\n---\r\n- hosts: localhost\r\n  vars:\r\n    vpc_id: <<REMOVED>>\r\n  tasks:\r\n    - name: Test self referencing security group \r\n      local_action:\r\n        module: ec2_group\r\n        name: 'self_referencing_group'\r\n        description: 'Default Security Group'\r\n        region: 'eu-west-1'\r\n        vpc_id: '{{ vpc_id }}'\r\n        rules:\r\n          - proto: udp \r\n            from_port: 0 \r\n            to_port: 65535\r\n            group_name: 'self_referencing_group'\r\n        rules_egress:\r\n          - proto: all \r\n            from_port: -1 \r\n            to_port: -1\r\n            cidr_ip: 0.0.0.0/0\r\n```\r\n\r\nreturns\r\n\r\n```\r\nfailed: [localhost] => {\"failed\": true, \"parsed\": false}\r\ninvalid output was: Traceback (most recent call last):\r\n  File \"/Users/205708/.ansible/tmp/ansible-tmp-1401392813.67-129993790148010/ec2_group\", line 1739, in <module>\r\n    main()\r\n  File \"/Users/205708/.ansible/tmp/ansible-tmp-1401392813.67-129993790148010/ec2_group\", line 267, in main\r\n    group_id, ip, target_group_created = get_target_from_rule(rule, name, groups)\r\n  File \"/Users/205708/.ansible/tmp/ansible-tmp-1401392813.67-129993790148010/ec2_group\", line 153, in get_target_from_rule\r\n    group_id = group.id\r\nNameError: global name 'group' is not defined\r\n\r\n\r\nFATAL: all hosts have already failed -- aborting\r\n```\r\n\r\n\r\nThis seems to have beed introduced with commit  77d7165dde0b5f5642ec3667854d55ca2482602c\r\n\r\n\r\nBy moving the code to the function get_target_from_rule, the code loses access to group. \r\n\r\n\r\n##### Steps To Reproduce:\r\n\r\nEdit above playbook with a vpc id and run \r\n\r\n##### Expected Results:\r\n\r\nSecurity group created with appropriate rules. \r\n\r\n##### Actual Results:\r\n```\r\nfailed: [localhost] => {\"failed\": true, \"parsed\": false}\r\ninvalid output was: Traceback (most recent call last):\r\n  File \"/Users/205708/.ansible/tmp/ansible-tmp-1401392813.67-129993790148010/ec2_group\", line 1739, in <module>\r\n    main()\r\n  File \"/Users/205708/.ansible/tmp/ansible-tmp-1401392813.67-129993790148010/ec2_group\", line 267, in main\r\n    group_id, ip, target_group_created = get_target_from_rule(rule, name, groups)\r\n  File \"/Users/205708/.ansible/tmp/ansible-tmp-1401392813.67-129993790148010/ec2_group\", line 153, in get_target_from_rule\r\n    group_id = group.id\r\nNameError: global name 'group' is not defined\r\n```\r\n\r\nFATAL: all hosts have already failed -- aborting\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/227149723","html_url":"https://github.com/ansible/ansible/issues/7592#issuecomment-227149723","issue_url":"https://api.github.com/repos/ansible/ansible/issues/7592","id":227149723,"user":{"login":"matthewdaize","id":3209700,"avatar_url":"https://avatars.githubusercontent.com/u/3209700?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewdaize","html_url":"https://github.com/matthewdaize","followers_url":"https://api.github.com/users/matthewdaize/followers","following_url":"https://api.github.com/users/matthewdaize/following{/other_user}","gists_url":"https://api.github.com/users/matthewdaize/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewdaize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewdaize/subscriptions","organizations_url":"https://api.github.com/users/matthewdaize/orgs","repos_url":"https://api.github.com/users/matthewdaize/repos","events_url":"https://api.github.com/users/matthewdaize/events{/privacy}","received_events_url":"https://api.github.com/users/matthewdaize/received_events","type":"User","site_admin":false},"created_at":"2016-06-20T13:58:37Z","updated_at":"2016-06-20T13:58:37Z","body":"Sorry to re-address this, but we have run into this same issue presently. The current solution is to run a second time as the first time it creates a blank security group after presenting an error. \r\n\r\nBecause you need to create the security group before you can reconcile its' rules, would it not be better to refactor it so that it creates all the groups before applying the rules to each?"}}
{"actor":{"display_login":"matthewdaize"}}