---
# ============================================================================
# Configure Physical Interfaces
# ============================================================================
- name: Get current interface configuration from firewall
ansible.builtin.uri:
url: "https://{{ sophos_mgmt_host }}:{{ sophos_mgmt_port }}/webconsole/APIController?reqxml={{ sophos_api_username }}{{ sophos_api_password }}"
method: POST
validate_certs: "{{ sophos_validate_certs }}"
headers:
Content-Type: "application/x-www-form-urlencoded"
return_content: true
status_code: [200]
register: current_interfaces
no_log: "{{ sophos_no_log_sensitive }}"
tags: ['interfaces']
- name: Parse current interface names
ansible.builtin.set_fact:
existing_interfaces: "{{ current_interfaces.content | regex_findall('(.*?)') }}"
tags: ['interfaces']
- name: Display existing interfaces
ansible.builtin.debug:
msg: "Found {{ existing_interfaces | length }} existing interfaces: {{ existing_interfaces | join(', ') }}"
tags: ['interfaces']
# Loop through each interface and configure it
- name: Configure physical interface {{ item.name }}
ansible.builtin.uri:
url: "https://{{ sophos_mgmt_host }}:{{ sophos_mgmt_port }}/webconsole/APIController"
method: POST
validate_certs: "{{ sophos_validate_certs }}"
headers:
Content-Type: "application/x-www-form-urlencoded"
body: "reqxml={{ lookup('template', 'interface.json.j2') | urlencode }}"
status_code: [200, 201]
timeout: "{{ sophos_api_timeout }}"
loop: "{{ sophos_interfaces }}"
loop_control:
label: "{{ item.name }} ({{ item.zone }})"
register: interface_result
no_log: "{{ sophos_no_log_sensitive }}"
changed_when: "'successful' in interface_result.content | lower or '200' in interface_result.content"
failed_when: "'error' in interface_result.content | lower"
tags: ['interfaces']
- name: Display interface configuration results
ansible.builtin.debug:
msg: "Configured {{ sophos_interfaces | length }} interfaces successfully"
tags: ['interfaces']