Files
chittick_projects/sophos-xgs-ansible/roles/sophos_network/tasks/vlans.yml
Jake Kasper 4f1e8d3add Claude 1
2025-12-09 09:33:48 -06:00

53 lines
2.0 KiB
YAML

---
# ============================================================================
# Configure VLAN Interfaces
# ============================================================================
- name: Get current VLAN configuration from firewall
ansible.builtin.uri:
url: "https://{{ sophos_mgmt_host }}:{{ sophos_mgmt_port }}/webconsole/APIController?reqxml=<Request><Login><Username>{{ sophos_api_username }}</Username><Password>{{ sophos_api_password }}</Password></Login><Get><VLANInterface/></Get></Request>"
method: POST
validate_certs: "{{ sophos_validate_certs }}"
headers:
Content-Type: "application/x-www-form-urlencoded"
return_content: true
status_code: [200]
register: current_vlans
no_log: "{{ sophos_no_log_sensitive }}"
tags: ['vlans']
- name: Parse current VLAN names
ansible.builtin.set_fact:
existing_vlans: "{{ current_vlans.content | regex_findall('<Name>(.*?)</Name>') }}"
tags: ['vlans']
- name: Display existing VLANs
ansible.builtin.debug:
msg: "Found {{ existing_vlans | length }} existing VLANs: {{ existing_vlans | join(', ') }}"
tags: ['vlans']
# Loop through each VLAN and configure it
- name: Configure VLAN 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', 'vlan.json.j2') | urlencode }}"
status_code: [200, 201]
timeout: "{{ sophos_api_timeout }}"
loop: "{{ sophos_vlans }}"
loop_control:
label: "{{ item.name }} (VLAN {{ item.vlan_id }})"
register: vlan_result
no_log: "{{ sophos_no_log_sensitive }}"
changed_when: "'successful' in vlan_result.content | lower or '200' in vlan_result.content"
failed_when: "'error' in vlan_result.content | lower"
tags: ['vlans']
- name: Display VLAN configuration results
ansible.builtin.debug:
msg: "Configured {{ sophos_vlans | length }} VLANs successfully"
tags: ['vlans']