ansible-community / molecule-plugins

Collection on molecule plugins
MIT License
109 stars 73 forks source link

Fix race condition in obtaining the public IP for ec2 (#43) #70

Closed danielpodwysocki closed 1 year ago

danielpodwysocki commented 1 year ago

Fixes https://github.com/ansible-community/molecule-plugins/issues/43

This prevents a race condition where we attempt to look up the public IP before an interface is assigned to the instance.

An instance in a "running" state will always have this completed - a "started" one not necessarily.

This would then go on and fail when this module is called (https://github.com/ansible-community/molecule-plugins/blob/7fe6accd324a11371bef4ea8db3957234cfda429/src/molecule_plugins/ec2/cookiecutter/%7B%7Bcookiecutter.molecule_directory%7D%7D/%7B%7Bcookiecutter.scenario_name%7D%7D/create.yml#L264)

        - name: Collect instance configs
          set_fact:
            instance_config:
              instance: "{{ item.name }}"
              address: "{{ item.assign_public_ip | ternary(instance.public_ip_address, instance.private_ip_address) }}"
              user: "{{ item.ssh_user }}"
              port: "{{ item.ssh_port }}"
              identity_file: "{{ item.private_key_path }}"
              instance_ids:
                - "{{ instance.instance_id }}"
          vars:
            instance: "{{ ec2_instances.results[index].instances[0] }}"
          loop: "{{ platforms }}"
          loop_control:
            index_var: index
            label: "{{ item.name }}"
          register: instance_configs
ssbarnea commented 1 year ago

Please raise this towards the new code location at https://github.com/ansible-community/molecule-plugins

danielpodwysocki commented 1 year ago

@ssbarnea This had already been opened at the new repo. Can we get this PR reopened?

danielpodwysocki commented 1 year ago

Any news on this PR?

apatard commented 1 year ago

@danielpodwysocki damn. forgot that gh rebase is messing with the commit authorship, sorry. Feel free to push force a commit with proper authorship if you care. If you don't mind it, say it too and I'll merge the PR.

apatard commented 1 year ago

after checking seems it's fine. Sorry for the noise, I've yet to learn how to deal with github interface. I'm going to merge the PR then.