This commit is contained in:
2026-06-01 10:41:54 +03:00
parent 5053c1fd96
commit 3baf668cef

View File

@@ -1256,7 +1256,7 @@
DIGITS="{{ inventory_hostname | regex_replace('[^0-9]', '') }}"
sshpass -p '{{ dev1_pass }}' ssh {{ ssh_opts_common }} \
"{{ dev1_user }}@{{ ansible_host|default(inventory_hostname) }}" \
"cat /var/run/lldp_server.json 2>/dev/null | grep -Ei ikeja${DIGITS} -A 10 | grep address | grep -vE 'subtype|ipv6' | awk -F'\"' '{ print \$4 }' | head -n1"
"cat /var/run/lldp_server.json 2>/dev/null | grep ${DIGITS} -A 10 | grep address | grep -vE 'subtype|ipv6' | awk -F'\"' '{ print \$4 }' | head -n1"
register: lldp_ip_raw
changed_when: false
failed_when: false
@@ -1375,7 +1375,7 @@
DIGITS="{{ inventory_hostname | regex_replace('[^0-9]', '') }}"
sshpass -p '{{ dev1_pass }}' ssh {{ ssh_opts_common }} \
"{{ dev1_user }}@{{ ansible_host|default(inventory_hostname) }}" \
"cat /var/run/lldp_server.json 2>/dev/null | grep -Ei ikeja${DIGITS} -A 15 | grep 'address_ipv6' | awk -F'\\\"' '{ print \\$4 }' | head -n1"
"cat /var/run/lldp_server.json 2>/dev/null | grep ${DIGITS} -A 15 | grep 'address_ipv6' | awk -F'\\\"' '{ print \\$4 }' | head -n1"
args:
executable: /bin/bash
register: lldp_ip6_raw
@@ -1706,7 +1706,7 @@
delegate_to: localhost
shell: |
PORT="{{ _local_port }}"
sshpass -f "{{ dev2_passfile_used }}" ssh {{ ssh_opts_common }} -o ConnectTimeout={{ ssh_timeout }} -p "$PORT" "{{ dev2_ssh_user }}@127.0.0.1" 'f=$(ls -1 /root/prepared_backup_* 2>/dev/null | head -n1); f=${f##*/}; v=$(printf "%s\n" "$f" | sed -nE "s/^prepared_backup_.*-([0-9]+\.[0-9]+\.[0-9]+)-r([0-9]+)$/\1/p"); r=$(printf "%s\n" "$f" | sed -nE "s/^prepared_backup_.*-([0-9]+\.[0-9]+\.[0-9]+)-r([0-9]+)$/\2/p"); [ -n "$v" ] && [ -n "$r" ] && echo "$v rev $r" || true'
sshpass -f "{{ dev2_passfile_used }}" ssh {{ ssh_opts_common }} -o ConnectTimeout={{ ssh_timeout }} -p "$PORT" "{{ dev2_ssh_user }}@127.0.0.1" "f=$(ls -1 /root/prepared_backup_* 2>/dev/null | head -n1); f=${f##*/prepared_backup_}; v=${f%-r*}; r=${f##*-r}; [ -n "$v" ] && [ -n "$r" ] && echo "$v rev $r" || true"
args:
executable: /bin/bash
register: dev2_fwver_backup_marker_tunnel
@@ -1723,7 +1723,7 @@
- dev2_passfile_used_lldp != 'NONE'
delegate_to: localhost
shell: |
sshpass -f "{{ dev2_passfile_used_lldp }}" ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o ConnectTimeout=15 "{{ dev2_ssh_user }}@{{ lldp_dev2_ip }}" 'f=$(ls -1 /root/prepared_backup_* 2>/dev/null | head -n1); f=${f##*/}; v=$(printf "%s\n" "$f" | sed -nE "s/^prepared_backup_.*-([0-9]+\.[0-9]+\.[0-9]+)-r([0-9]+)$/\1/p"); r=$(printf "%s\n" "$f" | sed -nE "s/^prepared_backup_.*-([0-9]+\.[0-9]+\.[0-9]+)-r([0-9]+)$/\2/p"); [ -n "$v" ] && [ -n "$r" ] && echo "$v rev $r" || true'
sshpass -f "{{ dev2_passfile_used_lldp }}" ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o ConnectTimeout=15 "{{ dev2_ssh_user }}@{{ lldp_dev2_ip }}" "f=$(ls -1 /root/prepared_backup_* 2>/dev/null | head -n1); f=${f##*/prepared_backup_}; v=${f%-r*}; r=${f##*-r}; [ -n "$v" ] && [ -n "$r" ] && echo "$v rev $r" || true"
args:
executable: /bin/bash
register: dev2_fwver_backup_marker_lldp
@@ -1748,7 +1748,7 @@
exit 0
fi
sshpass -p '{{ dev1_pass }}' ssh {{ ssh_opts_common }} "{{ dev1_user }}@{{ ansible_host|default(inventory_hostname) }}" "sshpass -f '/tmp/${F}' ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o ConnectTimeout={{ ssh_timeout }} '{{ dev2_ssh_user }}@\[${IP6}%{{ dev1_iface }}\]' 'f=\$(ls -1 /root/prepared_backup_* 2>/dev/null | head -n1); f=\${f##*/}; v=\$(printf \"%s\n\" \"\$f\" | sed -nE \"s/^prepared_backup_.*-([0-9]+\.[0-9]+\.[0-9]+)-r([0-9]+)$/\\1/p\"); r=\$(printf \"%s\n\" \"\$f\" | sed -nE \"s/^prepared_backup_.*-([0-9]+\.[0-9]+\.[0-9]+)-r([0-9]+)$/\\2/p\"); [ -n \"\$v\" ] && [ -n \"\$r\" ] && echo \"\$v rev \$r\" || true'"
sshpass -p '{{ dev1_pass }}' ssh {{ ssh_opts_common }} "{{ dev1_user }}@{{ ansible_host|default(inventory_hostname) }}" "sshpass -f '/tmp/${F}' ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o ConnectTimeout={{ ssh_timeout }} '{{ dev2_ssh_user }}@\[${IP6}%{{ dev1_iface }}\]' 'f=\$(ls -1 /root/prepared_backup_* 2>/dev/null | head -n1); f=\${f##*/prepared_backup_}; v=\${f%-r*}; r=\${f##*-r}; [ -n "\$v" ] && [ -n "\$r" ] && echo "\$v rev \$r" || true'"
args:
executable: /bin/bash
register: dev2_fwver_backup_marker_lldp6
@@ -2377,6 +2377,144 @@
non_ts_diff_found: true
changed_when: false
# ----------------------- Dev2 default gateway interface → indoor_defgw -----------------------
- name: Dev2 | Read default gateway interface (tunnel)
when:
- tunnel_ok | default(false)
- dev2_passfile_used != 'NONE'
delegate_to: localhost
shell: |
PORT="{{ _local_port }}"
sshpass -f "{{ dev2_passfile_used }}" ssh {{ ssh_opts_common }} -o ConnectTimeout={{ ssh_timeout }} -p "$PORT" "{{ dev2_ssh_user }}@127.0.0.1" "ip route show 2>/dev/null | grep default | awk '{print \$NF}' | head -n1 || true"
args:
executable: /bin/bash
register: dev2_defgw_tunnel
changed_when: false
failed_when: false
ignore_errors: true
- name: Dev2 | Read default gateway interface (LLDP IPv4)
when:
- tunnel_ok | default(false)
- dev2_passfile_used == 'NONE'
- (lldp_dev2_ip | default('') | length) > 0
- dev2_passfile_used_lldp is defined
- dev2_passfile_used_lldp != 'NONE'
delegate_to: localhost
shell: |
sshpass -f "{{ dev2_passfile_used_lldp }}" ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o ConnectTimeout=15 "{{ dev2_ssh_user }}@{{ lldp_dev2_ip }}" "ip route show 2>/dev/null | grep default | awk '{print \$NF}' | head -n1 || true"
args:
executable: /bin/bash
register: dev2_defgw_lldp
changed_when: false
failed_when: false
ignore_errors: true
- name: Dev2 | Read default gateway interface (LLDP IPv6 via Dev1)
when:
- tunnel_ok | default(false)
- dev2_passfile_used == 'NONE'
- (dev2_passfile_used_lldp is not defined or dev2_passfile_used_lldp == 'NONE')
- lldp_dev2_ip6 is defined
- lldp_dev2_ip6 | length > 0
- dev2_passfile_used_lldp6 is defined
- dev2_passfile_used_lldp6 != 'NONE'
delegate_to: localhost
shell: |
IP6="{{ lldp_dev2_ip6 }}"
F="{{ dev2_passfile_used_lldp6 }}"
if [ -z "$IP6" ] || [ -z "$F" ] || [ "$F" = "NONE" ]; then
exit 0
fi
sshpass -p '{{ dev1_pass }}' ssh {{ ssh_opts_common }} "{{ dev1_user }}@{{ ansible_host|default(inventory_hostname) }}" "sshpass -f '/tmp/${F}' ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o ConnectTimeout={{ ssh_timeout }} '{{ dev2_ssh_user }}@\[${IP6}%{{ dev1_iface }}\]' "ip route show 2>/dev/null | grep default | awk '{print \\\$NF}' | head -n1 || true""
args:
executable: /bin/bash
register: dev2_defgw_lldp6
changed_when: false
failed_when: false
ignore_errors: true
- name: Dev2 | Select default gateway interface output
delegate_to: localhost
set_fact:
indoor_defgw_raw: >-
{{
(dev2_defgw_tunnel.stdout | default('') | trim)
if (
(dev2_defgw_tunnel is defined) and
((dev2_defgw_tunnel.stdout | default('') | trim | length) > 0)
)
else (
(dev2_defgw_lldp.stdout | default('') | trim)
if (
(dev2_defgw_lldp is defined) and
((dev2_defgw_lldp.stdout | default('') | trim | length) > 0)
)
else (
(dev2_defgw_lldp6.stdout | default('') | trim)
if (
(dev2_defgw_lldp6 is defined) and
((dev2_defgw_lldp6.stdout | default('') | trim | length) > 0)
)
else ''
)
)
}}
changed_when: false
- name: Dev2 | Normalize indoor_defgw value
delegate_to: localhost
set_fact:
indoor_defgw_value: >-
{{
'unavailable'
if (indoor_defgw_raw | default('') | trim) == ''
else (indoor_defgw_raw | default('') | trim)
}}
changed_when: false
- name: Scan tracking | Dev2 indoor_defgw outcome
delegate_to: localhost
set_fact:
scan_ok: "{{ scan_ok + (['indoor_defgw'] if ((indoor_defgw_value | default('unavailable')) != 'unavailable') else []) }}"
scan_fail: "{{ scan_fail + (['indoor_defgw=unavailable'] if ((indoor_defgw_value | default('unavailable')) == 'unavailable') else []) }}"
changed_when: false
- name: Publish Dev2 indoor_defgw custom field
when:
- (not (nb_baseline_ok | default(false))) or ((indoor_defgw_value) != (nb_custom_fields_current.get('indoor_defgw')))
delegate_to: localhost
uri:
url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish"
method: POST
user: "{{ rmq_user }}"
password: "{{ rmq_pass }}"
force_basic_auth: true
status_code: 200
headers: { content-type: "application/json" }
body_format: json
body:
properties: { content_type: "application/json" }
routing_key: "{{ control_queue }}"
payload: "{{ {
'inscope_device': (ansible_hostname|default(inventory_hostname)),
'task_name': 'custom_field_set',
'task_add1': 'indoor_defgw',
'task_result': indoor_defgw_value
} | to_json }}"
payload_encoding: "string"
changed_when: false
- name: Delta tracking | Mark changed indoor_defgw
when:
- (not (nb_baseline_ok | default(false))) or ((indoor_defgw_value) != (nb_custom_fields_current.get('indoor_defgw')))
delegate_to: localhost
set_fact:
non_ts_diff_found: true
changed_when: false
# ----------------------- SOT timestamp (container local time) → sot_ts -----------------------
- name: SOT ts | Get container timestamp
delegate_to: localhost