53 lines
2.2 KiB
YAML
53 lines
2.2 KiB
YAML
---
|
|
# ============================================================================
|
|
# Configure Static Routes
|
|
# ============================================================================
|
|
|
|
- name: Get current static route 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><StaticRoute/></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_routes
|
|
no_log: "{{ sophos_no_log_sensitive }}"
|
|
tags: ['routes']
|
|
|
|
- name: Parse current route names
|
|
ansible.builtin.set_fact:
|
|
existing_routes: "{{ current_routes.content | regex_findall('<Name>(.*?)</Name>') }}"
|
|
tags: ['routes']
|
|
|
|
- name: Display existing static routes
|
|
ansible.builtin.debug:
|
|
msg: "Found {{ existing_routes | length }} existing static routes: {{ existing_routes | join(', ') }}"
|
|
tags: ['routes']
|
|
|
|
# Loop through each static route and configure it
|
|
- name: Configure static route {{ 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', 'static_route.json.j2') | urlencode }}"
|
|
status_code: [200, 201]
|
|
timeout: "{{ sophos_api_timeout }}"
|
|
loop: "{{ sophos_static_routes }}"
|
|
loop_control:
|
|
label: "{{ item.name }} ({{ item.destination }}/{{ item.netmask }} via {{ item.gateway }})"
|
|
register: route_result
|
|
no_log: "{{ sophos_no_log_sensitive }}"
|
|
changed_when: "'successful' in route_result.content | lower or '200' in route_result.content"
|
|
failed_when: "'error' in route_result.content | lower"
|
|
tags: ['routes']
|
|
|
|
- name: Display static route configuration results
|
|
ansible.builtin.debug:
|
|
msg: "Configured {{ sophos_static_routes | length }} static routes successfully"
|
|
tags: ['routes']
|