Skip to content

Fix bug with multiple bastion hosts #9352

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

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

- name: Store bastion hostname as a fact
set_fact:
bastion_hostname: "{{groups['bastions'].0 }}"
bastion_hostname: "{{ groups.bastions | sort | first }}"
# This is where the ssh_config file will be created, this file is used to
# define the communication method to all the hosts in the deployment
ansible_ssh_config: "{{output_dir}}/{{ env_type }}_{{ guid }}_ssh_conf"
Expand Down
23 changes: 13 additions & 10 deletions ansible/roles-infra/infra-ec2-create-inventory/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@
- create_inventory
- must

# Find the bastion
- name: Find the bastion in this batch of host
set_fact:
local_bastion: "{{ item.tags.internaldns }}"
when:
- item.state.name != 'terminated'
- '"bastions" in item.tags.AnsibleGroup'
with_items: "{{ ec2_info['instances'] }}"
- name: Find the bastion in this batch of hosts
loop: >-
{{ ec2_info.instances
| json_query("[?state.name != 'terminated' && tags.internaldns]")
| sort(attribute="tags.internaldns")
}}
loop_control:
label: "{{ item.tags.internaldns | default(item.private_dns_name) }}"
ignore_errors: true
loop_var: __instance
label: "{{ __instance.tags.internaldns }}"
when:
- "'bastions' in __instance.tags.AnsibleGroup | default('') | split(',')"
- local_bastion is undefined
set_fact:
local_bastion: "{{ __instance.tags.internaldns }}"

- name: Add hosts to the current inventory
add_host:
Expand Down
Loading