mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-07-14 04:43:09 +02:00
docker_container.running fails with an address-already-in-use error when a container holds a stale sobridge endpoint - either after its IP changes in pillar or after an unclean shutdown leaves the endpoint behind. Add the clear_stale_endpoint macro and call it from every enabled.sls whose container attaches to sobridge with a static IP. The macro force-disconnects the container from the network only when its current endpoint IP does not match the one salt is about to assign, so it is a no-op on a normal highstate. The strelka states use state IDs that differ from their container names, so those calls pass state_id explicitly. nginx resolves its IP through container_config, which varies by role.
13 lines
600 B
Django/Jinja
13 lines
600 B
Django/Jinja
{% macro clear_stale_endpoint(container, network, ipv4, state_id=None) %}
|
|
{{ container }}_{{ network }}_stale_endpoint:
|
|
cmd.run:
|
|
- name: docker network disconnect -f {{ network }} {{ container }} || true
|
|
- onlyif: docker inspect {{ container }}
|
|
- unless: >-
|
|
docker inspect -f
|
|
'{{ '{{' }} with index .NetworkSettings.Networks "{{ network }}" {{ '}}' }}{{ '{{' }} .IPAMConfig.IPv4Address {{ '}}' }}{{ '{{' }} end {{ '}}' }}'
|
|
{{ container }} 2>/dev/null | grep -qx '{{ ipv4 }}'
|
|
- require_in:
|
|
- docker_container: {{ state_id or container }}
|
|
{% endmacro %}
|