1035
This commit is contained in:
@@ -732,6 +732,164 @@
|
||||
- "DEV2 md5={{ dev2_config_md5.stdout | trim }}"
|
||||
- "Local md5={{ local_config_md5.stdout | trim }}"
|
||||
|
||||
- name: PHASE 1 | Set controller paths for DHCP conversion
|
||||
delegate_to: localhost
|
||||
ansible.builtin.set_fact:
|
||||
pppoe_to_dhcp_script: "/opt/containers/ansible-worker/app/pppoe_to_dhcp.py"
|
||||
dev2_config_dhcp_local_path: "{{ dev2_config_local_dir }}/dev2_config_dhcp_{{ inventory_hostname }}.json"
|
||||
dev2_config_dhcp_remote_path: "/tmp/config-dhcp.json"
|
||||
changed_when: false
|
||||
|
||||
- name: PHASE 1 | Abort if pppoe_to_dhcp.py is missing on controller
|
||||
delegate_to: localhost
|
||||
ansible.builtin.shell: |
|
||||
test -f "{{ pppoe_to_dhcp_script }}"
|
||||
args: { executable: /bin/bash }
|
||||
register: dhcp_script_present
|
||||
changed_when: false
|
||||
failed_when: dhcp_script_present.rc != 0
|
||||
|
||||
- name: PHASE 1 | Convert config.json -> config-dhcp.json (controller)
|
||||
delegate_to: localhost
|
||||
ansible.builtin.shell: |
|
||||
set -e
|
||||
python3 "{{ pppoe_to_dhcp_script }}" "{{ dev2_config_local_path }}" -o "{{ dev2_config_dhcp_local_path }}"
|
||||
args: { executable: /bin/bash }
|
||||
register: convert_run
|
||||
changed_when: true
|
||||
failed_when: convert_run.rc != 0
|
||||
|
||||
- name: PHASE 1 | Controller md5sum of generated config-dhcp.json
|
||||
delegate_to: localhost
|
||||
ansible.builtin.shell: |
|
||||
set -e
|
||||
md5sum "{{ dev2_config_dhcp_local_path }}" | awk '{print $1}'
|
||||
args: { executable: /bin/bash }
|
||||
register: local_dhcp_md5
|
||||
changed_when: false
|
||||
failed_when: (local_dhcp_md5.stdout | trim | length) == 0
|
||||
|
||||
- name: PHASE 1 | Upload config-dhcp.json to DEV2 (tunnel)
|
||||
when: dev2_conn_final == "tunnel"
|
||||
delegate_to: localhost
|
||||
ansible.builtin.shell: |
|
||||
set -e
|
||||
PORT="{{ _local_port }}"
|
||||
PASS="{{ dev2_passfile_used_tunnel }}"
|
||||
sshpass -f "$PASS" scp {{ ssh_opts_common }} \
|
||||
-P "$PORT" "{{ dev2_config_dhcp_local_path }}" \
|
||||
"{{ dev2_ssh_user }}@127.0.0.1:{{ dev2_config_dhcp_remote_path }}"
|
||||
args: { executable: /bin/bash }
|
||||
register: scp_up_tunnel
|
||||
changed_when: true
|
||||
failed_when: scp_up_tunnel.rc != 0
|
||||
|
||||
- name: PHASE 1 | Upload config-dhcp.json to DEV2 (direct LLDP IPv4)
|
||||
when: dev2_conn_final == "direct_lldp"
|
||||
delegate_to: localhost
|
||||
ansible.builtin.shell: |
|
||||
set -e
|
||||
HOST="{{ lldp_dev2_ip }}"
|
||||
PASS="{{ dev2_passfile_used_direct }}"
|
||||
sshpass -f "$PASS" scp {{ ssh_opts_common }} \
|
||||
"{{ dev2_config_dhcp_local_path }}" \
|
||||
"{{ dev2_ssh_user }}@${HOST}:{{ dev2_config_dhcp_remote_path }}"
|
||||
args: { executable: /bin/bash }
|
||||
register: scp_up_direct
|
||||
changed_when: true
|
||||
failed_when: scp_up_direct.rc != 0
|
||||
|
||||
- name: PHASE 1 | Upload config-dhcp.json to DEV2 (LLDP IPv4 fallback)
|
||||
when: dev2_conn_final == "lldp4_fallback"
|
||||
delegate_to: localhost
|
||||
ansible.builtin.shell: |
|
||||
set -e
|
||||
HOST="{{ lldp_dev2_ip }}"
|
||||
PASS="{{ dev2_passfile_used_lldp4 }}"
|
||||
sshpass -f "$PASS" scp {{ ssh_opts_common }} \
|
||||
"{{ dev2_config_dhcp_local_path }}" \
|
||||
"{{ dev2_ssh_user }}@${HOST}:{{ dev2_config_dhcp_remote_path }}"
|
||||
args: { executable: /bin/bash }
|
||||
register: scp_up_lldp4
|
||||
changed_when: true
|
||||
failed_when: scp_up_lldp4.rc != 0
|
||||
|
||||
- name: PHASE 1 | Upload config-dhcp.json to DEV2 (LLDP IPv6 via DEV1 nested; last resort)
|
||||
when: dev2_conn_final == "lldp6_via_dev1"
|
||||
delegate_to: localhost
|
||||
ansible.builtin.shell: |
|
||||
set -e
|
||||
IP6="{{ lldp_dev2_ip6 }}"
|
||||
F="{{ dev2_passfile_used_lldp6 }}"
|
||||
STAGE_ON_DEV1="/tmp/config-dhcp_{{ inventory_hostname }}.json"
|
||||
|
||||
sshpass -p "{{ dev1_pass }}" scp {{ ssh_opts_common }} \
|
||||
"{{ dev2_config_dhcp_local_path }}" \
|
||||
"{{ dev1_user }}@{{ ansible_host | default(inventory_hostname) }}:${STAGE_ON_DEV1}"
|
||||
|
||||
sshpass -p "{{ dev1_pass }}" ssh {{ ssh_opts_common }} \
|
||||
"{{ dev1_user }}@{{ ansible_host | default(inventory_hostname) }}" \
|
||||
"sshpass -f '/tmp/${F}' scp \
|
||||
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR \
|
||||
-o PreferredAuthentications=password -o PubkeyAuthentication=no -o NumberOfPasswordPrompts=1 \
|
||||
'${STAGE_ON_DEV1}' '{{ dev2_ssh_user }}@\[${IP6}%{{ dev1_iface }}\]':{{ dev2_config_dhcp_remote_path }}"
|
||||
|
||||
sshpass -p "{{ dev1_pass }}" ssh {{ ssh_opts_common }} \
|
||||
"{{ dev1_user }}@{{ ansible_host | default(inventory_hostname) }}" \
|
||||
"rm -f '${STAGE_ON_DEV1}' 2>/dev/null || true"
|
||||
args: { executable: /bin/bash }
|
||||
register: scp_up_lldp6
|
||||
changed_when: true
|
||||
failed_when: scp_up_lldp6.rc != 0
|
||||
|
||||
- name: PHASE 1 | DEV2 md5sum of uploaded config-dhcp.json via wrapper
|
||||
delegate_to: localhost
|
||||
ansible.builtin.shell: |
|
||||
export DEV2_CMD="md5sum {{ dev2_config_dhcp_remote_path }} 2>/dev/null | awk '{print \$1}'"
|
||||
{{ dev2_exec_cmd }}
|
||||
args: { executable: /bin/bash }
|
||||
register: dev2_dhcp_md5
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: PHASE 1 | Abort if DEV2 md5 for uploaded file is empty
|
||||
when: (dev2_dhcp_md5.stdout | default('') | trim | length) == 0
|
||||
ansible.builtin.fail:
|
||||
msg: "DEV2 md5sum for {{ dev2_config_dhcp_remote_path }} is empty; upload failed or md5sum unavailable."
|
||||
|
||||
- name: PHASE 1 | Compare controller vs DEV2 md5sum for config-dhcp.json (fail on mismatch)
|
||||
delegate_to: localhost
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
MD5 mismatch for config-dhcp.json:
|
||||
local={{ local_dhcp_md5.stdout | trim }},
|
||||
dev2={{ dev2_dhcp_md5.stdout | trim }},
|
||||
local_file={{ dev2_config_dhcp_local_path }},
|
||||
remote_file={{ dev2_config_dhcp_remote_path }}
|
||||
when: (local_dhcp_md5.stdout | trim) != (dev2_dhcp_md5.stdout | trim)
|
||||
|
||||
- name: PHASE 1 | Cleanup controller local config artifacts (only after md5 match)
|
||||
delegate_to: localhost
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- "{{ dev2_config_local_path }}"
|
||||
- "{{ dev2_config_dhcp_local_path }}"
|
||||
ignore_errors: true
|
||||
|
||||
- name: PHASE 1 | Debug DHCP conversion + upload + md5 verification
|
||||
when: debugging | bool
|
||||
delegate_to: localhost
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "Converted DHCP config: {{ dev2_config_dhcp_local_path }}"
|
||||
- "Uploaded to DEV2: {{ dev2_config_dhcp_remote_path }}"
|
||||
- "Local md5={{ local_dhcp_md5.stdout | trim }}"
|
||||
- "DEV2 md5={{ dev2_dhcp_md5.stdout | trim }}"
|
||||
|
||||
|
||||
|
||||
post_tasks:
|
||||
- name: Cleanup note
|
||||
delegate_to: localhost
|
||||
|
||||
Reference in New Issue
Block a user