{"action":"closed","issue":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/3160","repository_url":"https://api.github.com/repos/ansible/ansible-modules-core","labels_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/3160/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/3160/comments","events_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/3160/events","html_url":"https://github.com/ansible/ansible-modules-core/issues/3160","id":137627175,"number":3160,"title":"ec2_asg: Usage of replace_all_instances errors out if no instances exist yet","user":{"login":"wholroyd","id":147990,"avatar_url":"https://avatars3.githubusercontent.com/u/147990?v=4","gravatar_id":"","url":"https://api.github.com/users/wholroyd","html_url":"https://github.com/wholroyd","followers_url":"https://api.github.com/users/wholroyd/followers","following_url":"https://api.github.com/users/wholroyd/following{/other_user}","gists_url":"https://api.github.com/users/wholroyd/gists{/gist_id}","starred_url":"https://api.github.com/users/wholroyd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wholroyd/subscriptions","organizations_url":"https://api.github.com/users/wholroyd/orgs","repos_url":"https://api.github.com/users/wholroyd/repos","events_url":"https://api.github.com/users/wholroyd/events{/privacy}","received_events_url":"https://api.github.com/users/wholroyd/received_events","type":"User","site_admin":false},"labels":[{"id":437720344,"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/affects_2.1","name":"affects_2.1","color":"5319e7","default":false},{"id":382351767,"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/aws","name":"aws","color":"c5def5","default":false},{"id":132571937,"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/bug_report","name":"bug_report","color":"fbca04","default":false},{"id":132897218,"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/cloud","name":"cloud","color":"c7def8","default":false},{"id":414073372,"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/waiting_on_maintainer","name":"waiting_on_maintainer","color":"d93f0b","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-03-01T16:46:57Z","updated_at":"2017-09-12T01:44:03Z","closed_at":"2017-09-12T01:44:03Z","author_association":"CONTRIBUTOR","body":"##### Issue Type:\n- Bug Report\n##### Plugin Name:\n\nec2_asg\n##### Ansible Version:\n\n```\nansible 2.1.0\n  config file = /home/wholroyd/source/automation/ansible/ansible.cfg\n  configured module search path = ./library\n```\n##### Ansible Configuration:\n\nError is strictly related to module logic.\n##### Environment:\n\nFedora 23 server with everything running locally\n##### Summary:\n\nWhen attempting to standup an ASG and attempting to use the 'replace_all_instances' flag set to true, the module fails because it can't find any running instances. I'd like to be able to make this script re-runnable so that each time it's run, I'm able to change the related launch configuration. Not all ASGs have any running instances (think of two ASGs used in A/B testing with one empty), especially at creation time.\n##### Steps To Reproduce:\n\nCreate a launch configuration.\nCreate an asg with `replace_all_instances: true` referencing the launch configuration\n\n``` yaml\n- name: Ensure the existance of the new launch configuration\n  ec2_lc:\n    region: \"{{ region }}\"\n    profile: \"{{ account }}\"\n    state: present\n    name: \"{{ vpc_name }}-Routing-{{ timestamp }}\"\n    image_id: \"{{ cloud_ami.results[0].ami_id }}\"\n    instance_type: \"t2.small\"\n    instance_profile_name: \"{{ account }}-routing-monitor\"\n    key_name: \"{{ account }}_{{ region }}\"\n    assign_public_ip: yes\n    security_groups: \"{{ existing_groups_list }}\"\n    user_data: \"{{ lookup('file', 'roles/account_infrastructure/files/infrastructure-routing.sh') }}\"\n\n- name: \"Verify the virtual private cloud subnet to use\"\n  ec2_vpc_subnet_facts:\n    region: \"{{ region }}\"\n    profile: \"{{ account }}\"\n    filters:\n      \"tag:Name\" : \"{{ vpc_name }}-Core\"  \n      \"availability-zone\" : \"{{ datacenter_regions_zones[region][0] }}\"  \n  register: account_cloud_vpc_subnets_a\n- debug: var=account_cloud_vpc_subnets_a\n\n- name: Ensure the existence of the new Auto Scale Group in zone A\n  ec2_asg:\n    region: \"{{ region }}\"\n    profile: \"{{ account }}\"\n    state: present\n    name: \"{{ vpc_name }}-Routing-{{ datacenter_regions_zones[region][0] }}\"\n    min_size: 0\n    max_size: 1\n    desired_capacity: 1\n    availability_zones: [ \"{{ datacenter_regions_zones[region][0] }}\" ]\n    vpc_zone_identifier: \"{{ account_cloud_vpc_subnets_a.subnets[0].id }}\"\n    launch_config_name: \"{{ vpc_name }}-Routing-{{ timestamp }}\"\n    wait_for_instances: false\n    replace_all_instances: true\n```\n##### Expected Results:\n1. Creation of ASG without any issue.\n2. Modification of ASG and instances replaced (if they exist)\n##### Actual Results:\n\nThe module fails to create the ASG because it doesn't hold any instances yet.\n\n```\nESTABLISH LOCAL CONNECTION FOR USER: wholroyd\nlocalhost EXEC /bin/sh -c '( umask 22 && mkdir -p \"` echo $HOME/.ansible/tmp/ansible-tmp-1456849907.05-42662666435855 `\" && echo \"` echo $HOME/.ansible/tmp/ansible-tmp-1456849907.05-42662666435855 `\" )'\nlocalhost PUT /tmp/tmp9W7ZbD TO /home/wholroyd/.ansible/tmp/ansible-tmp-1456849907.05-42662666435855/ec2_asg\nlocalhost EXEC /bin/sh -c 'LANG=C LC_ALL=C LC_MESSAGES=C /usr/bin/python /home/wholroyd/.ansible/tmp/ansible-tmp-1456849907.05-42662666435855/ec2_asg; rm -rf \"/home/wholroyd/.ansible/tmp/ansible-tmp-1456849907.05-42662666435855/\" > /dev/null 2>&1'\nAn exception occurred during task execution. The full traceback is:\nTraceback (most recent call last):\n  File \"/home/wholroyd/.ansible/tmp/ansible-tmp-1456849907.05-42662666435855/ec2_asg\", line 3104, in <module>\n    main()\n  File \"/home/wholroyd/.ansible/tmp/ansible-tmp-1456849907.05-42662666435855/ec2_asg\", line 3098, in main\n    replace_changed, asg_properties=replace(connection, module)\n  File \"/home/wholroyd/.ansible/tmp/ansible-tmp-1456849907.05-42662666435855/ec2_asg\", line 2832, in replace\n    instances = props['instances']\nKeyError: 'instances'\n\nfatal: [localhost]: FAILED! => {\"changed\": false, \"failed\": true, \"invocation\": {\"module_name\": \"ec2_asg\"}, \"parsed\": false}\n        to retry, use: --limit @account.retry\n```\n"}}
{"actor":{"display_login":"ansibot"}}