Claude 1
This commit is contained in:
52
sophos-xgs-ansible/roles/sophos_network/tasks/routes.yml
Normal file
52
sophos-xgs-ansible/roles/sophos_network/tasks/routes.yml
Normal file
@@ -0,0 +1,52 @@
|
||||
---
|
||||
# ============================================================================
|
||||
# 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']
|
||||
Reference in New Issue
Block a user