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

EC2 public_ip_address not always set after ec2_instance creation #43

Closed
kuwv opened this issue Jul 29, 2022 · 8 comments · Fixed by #70
Closed

EC2 public_ip_address not always set after ec2_instance creation #43

kuwv opened this issue Jul 29, 2022 · 8 comments · Fixed by #70
Labels
ec2 Amazon EC2

Comments

@kuwv
Copy link

kuwv commented Jul 29, 2022

Overview

While creating EC2 instances with the default create playbook the "Collect instance configs" task will fail randomly. This is due to the ec2_instance (set with assign_public_ip) being created but not waiting to be populated with the public IP address. The register attribute is then undefined when that above task is run.

ansible            6.1.0
ansible-compat     2.2.0
ansible-core       2.13.2
molecule           3.5.1
molecule-ec2       0.3

I attempted downgrading from molecule 0.4.* to 0.3.5. with corresponding downgrade for molecule-ec2 also. It did not work.

This issue is obviously with ec2_instance itself but since it directly effects molecule-ec2 I submitted this issue for tracking purposes. Also, this could potentially be resolved with different designs without directly modify ec2_instance.

@Aftermath
Copy link

@kuwv did you come up with any workaround for this, such as adding an additional query after instance creation?
I seem to hit this more often than not now.

@kuwv
Copy link
Author

kuwv commented Sep 26, 2022

@Aftermath I had to shift my attention to other work. I don't remember if there was an existing issue or if I submitted one for the ec2_instance module. LMC.

@Tjhayhay
Copy link

I think you just need to add the following to the create.yml

- name: Create ephemeral EC2 instance(s)
  amazon.aws.ec2_instance:
    state: "running"

According to this https://stackoverflow.com/a/71269582

@kuwv
Copy link
Author

kuwv commented Sep 29, 2022

@Tjhayhay yeah it definitely seems it's just as simple as that.

One correction though is that the molecule role needs to set it correctly.

@Aftermath
Copy link

Agreed, this seems to resolve the issue.
I originally went about it a different way thinking it was a strange timing issue, as I missed the existence of 'state' during my review.
Thanks.

@ssbarnea ssbarnea added the ec2 Amazon EC2 label Jan 5, 2023
@ssbarnea ssbarnea transferred this issue from ansible-community/molecule-ec2 Jan 5, 2023
@danielpodwysocki
Copy link
Contributor

danielpodwysocki commented Jan 7, 2023

Ran into this recently - is anyone working on a patch for the default cookiecutter? In case nobody's got the bandwidth, I'd be happy to make a PR for this as well.

@kuwv
Copy link
Author

kuwv commented Jan 7, 2023

@danielpodwysocki sure that would be great. I've been waiting for some free time to do it but just haven't had time.

@danielpodwysocki
Copy link
Contributor

danielpodwysocki commented Jan 7, 2023

@kuwv Awesome - I bumped a PR here. #70

apatard pushed a commit that referenced this issue Apr 12, 2023
Fix race condition in obtaining the public IP for ec2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ec2 Amazon EC2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants