Skip to content

Fix port conflict when deploying multiple IOCs in a single run#170

Open
sligara7 wants to merge 1 commit intomainfrom
fix/multi-ioc-port-assignment
Open

Fix port conflict when deploying multiple IOCs in a single run#170
sligara7 wants to merge 1 commit intomainfrom
fix/multi-ioc-port-assignment

Conversation

@sligara7
Copy link
Contributor

Summary

  • When deploying multiple IOCs in one AAP run (comma-separated in the deploy template), all IOCs after the first were assigned the same procserv port, causing port conflicts
  • Root cause: 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 set it via set_fact
  • Fix: reset deploy_ioc_nextport using set_fact (which can override a prior set_fact) and change > to >= to handle the edge case where max port equals the default

Test plan

  • Deploy a single IOC — verify it gets a unique port as before
  • Deploy multiple IOCs in one run (comma-separated) — verify each gets a unique, incrementing port
  • Re-deploy an existing IOC — verify it retains its existing port from the config file

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 11, 2026 20:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes procServ port conflicts when deploying multiple IOCs in a single Ansible run by ensuring the “next port” counter is properly reset per loop iteration and by handling the edge case where the current max port equals the default start port.

Changes:

  • Adjust port selection condition from > to >= when computing the next available port.
  • Reset deploy_ioc_nextport via set_fact at the start of each IOC deployment iteration to avoid include_vars being ignored due to Ansible precedence.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
roles/deploy_ioc/tasks/update-config.yml Updates the conditional logic used to compute the next available procServ port.
roles/deploy_ioc/tasks/set-facts.yml Adds an explicit per-iteration reset of the port counter using set_fact.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sligara7 sligara7 force-pushed the fix/multi-ioc-port-assignment branch from 3cb4c1b to 95dbeb8 Compare February 11, 2026 21:11
@sligara7 sligara7 requested a review from jwlodek February 11, 2026 21:42
@sligara7 sligara7 force-pushed the fix/multi-ioc-port-assignment branch 3 times, most recently from c0127e8 to 157c0ee Compare February 12, 2026 16:34
set_fact has higher precedence than include_vars in Ansible, so the
include_vars reset at the start of each loop iteration was silently
ignored after the first iteration set variables via set_fact. This
caused all IOCs after the first to reuse the same port number, and
could also leak deploy_ioc_executable, deploy_ioc_template_root_path,
and deploy_ioc_dbpf_list between IOCs.

Fix by:
- Loading role defaults into a namespaced dict and resetting all
  default variables via set_fact each iteration (looping over
  dict2items), sourced from that namespace as single source of truth.
  deploy_ioc_default_env is excluded because it references ioc.type
  which is not yet available and is never set via set_fact.
- Loading device type vars into a namespace and promoting them to
  set_fact precedence so they override the defaults reset.
  deploy_ioc_template_root_path is resolved separately after module
  installation since many device types reference
  deploy_ioc_required_module_path in a Jinja2 template.
- 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.
- Always setting install_module_leaf_executable (defaulting to empty
  string) so stale values from a prior deploy_ioc iteration cannot
  leak across mixed device types. The consumer now checks for
  non-empty rather than just defined.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sligara7 sligara7 force-pushed the fix/multi-ioc-port-assignment branch from 157c0ee to 822d66d Compare February 12, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants