Skip to content

Commit 3cb4c1b

Browse files
sligara7claude
andcommitted
Fix port conflict when deploying multiple IOCs in a single run
set_fact has higher precedence than include_vars in Ansible, so the include_vars reset of deploy_ioc_nextport at the start of each loop iteration was silently ignored after the first iteration's set_fact. This caused all IOCs after the first to reuse the same port number. The same precedence issue affects deploy_ioc_executable, deploy_ioc_template_root_path, and deploy_ioc_dbpf_list, which could carry over between IOCs in a multi-IOC deployment. Fix by: - Loading defaults into a namespaced dict and resetting all affected per-IOC variables via set_fact each iteration, sourced from that dict so there is a single source of truth for default values. - Changing the port comparison from > to >= to handle the edge case where max port equals the default. - Removing deploy_ioc_loop_index from the port calculation, since the deployment is sequential and each iteration's config file is visible to the next via the find command. The index was causing ports to skip ahead unnecessarily. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3ba48a9 commit 3cb4c1b

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

roles/deploy_ioc/tasks/set-facts.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
ansible.builtin.include_vars:
55
file: defaults/main.yml
66

7+
- name: Load defaults into namespace for per-IOC reset
8+
ansible.builtin.include_vars:
9+
file: defaults/main.yml
10+
name: _deploy_ioc_defaults
11+
12+
- name: Reset per-IOC variables that may persist via set_fact from prior iterations
13+
ansible.builtin.set_fact:
14+
deploy_ioc_nextport: "{{ _deploy_ioc_defaults.deploy_ioc_nextport }}"
15+
deploy_ioc_executable: "{{ _deploy_ioc_defaults.deploy_ioc_executable }}"
16+
deploy_ioc_template_root_path: "{{ _deploy_ioc_defaults.deploy_ioc_template_root_path }}"
17+
deploy_ioc_dbpf_list: "{{ _deploy_ioc_defaults.deploy_ioc_dbpf_list }}"
18+
719
- name: Make sure IOC with given name is configured on host
820
ansible.builtin.fail:
921
msg: "IOC with name {{ deploy_ioc_ioc_name }} is not configured on host"

roles/deploy_ioc/tasks/update-config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
- name: Set next port number
3636
ansible.builtin.set_fact:
3737
deploy_ioc_nextport:
38-
"{{ deploy_ioc_current_max_port.stdout | int + deploy_ioc_loop_index + 1 }}" # yamllint disable-line rule:line-length
38+
"{{ deploy_ioc_current_max_port.stdout | int + 1 }}"
3939
when:
4040
deploy_ioc_current_max_port.stdout != "" and
41-
(deploy_ioc_current_max_port.stdout | int) > (deploy_ioc_nextport | int)
41+
(deploy_ioc_current_max_port.stdout | int) >= (deploy_ioc_nextport | int)
4242

4343
- name: Print next port number
4444
ansible.builtin.debug:

0 commit comments

Comments
 (0)