Claude 1
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
---
|
||||
# ============================================================================
|
||||
# Sophos Site-to-Site VPN Role - Main Tasks
|
||||
# ============================================================================
|
||||
|
||||
- name: Display site-to-site VPN configuration overview
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "======================================"
|
||||
- "Configuring Site-to-Site VPN Tunnels"
|
||||
- "======================================"
|
||||
- "Firewall: {{ inventory_hostname }}"
|
||||
- "Tunnels: {{ sophos_site_to_site_vpns | default([]) | length }}"
|
||||
tags: ['always']
|
||||
when: sophos_site_to_site_vpns is defined
|
||||
|
||||
- name: Skip site-to-site VPN configuration (not defined)
|
||||
ansible.builtin.debug:
|
||||
msg: "No site-to-site VPN tunnels defined for {{ inventory_hostname }}"
|
||||
when: sophos_site_to_site_vpns is not defined or sophos_site_to_site_vpns | length == 0
|
||||
tags: ['always']
|
||||
|
||||
- name: Get current IPsec connections 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><IPSecConnection/></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_ipsec_connections
|
||||
no_log: "{{ sophos_no_log_sensitive }}"
|
||||
when: sophos_site_to_site_vpns is defined and sophos_site_to_site_vpns | length > 0
|
||||
tags: ['vpn', 'site-to-site']
|
||||
|
||||
- name: Parse current IPsec connection names
|
||||
ansible.builtin.set_fact:
|
||||
existing_ipsec_connections: "{{ current_ipsec_connections.content | regex_findall('<Name>(.*?)</Name>') }}"
|
||||
when: sophos_site_to_site_vpns is defined and sophos_site_to_site_vpns | length > 0
|
||||
tags: ['vpn', 'site-to-site']
|
||||
|
||||
- name: Configure site-to-site VPN tunnel {{ 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', 'ipsec_connection.json.j2') | urlencode }}"
|
||||
status_code: [200, 201]
|
||||
timeout: "{{ sophos_api_timeout }}"
|
||||
loop: "{{ sophos_site_to_site_vpns }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }} ({{ item.local_gateway }} <-> {{ item.remote_gateway }})"
|
||||
register: vpn_result
|
||||
no_log: "{{ sophos_no_log_sensitive }}"
|
||||
when: sophos_site_to_site_vpns is defined and sophos_site_to_site_vpns | length > 0
|
||||
changed_when: "'successful' in vpn_result.content | lower"
|
||||
tags: ['vpn', 'site-to-site']
|
||||
|
||||
- name: Site-to-site VPN configuration completed
|
||||
ansible.builtin.debug:
|
||||
msg: "Configured {{ sophos_site_to_site_vpns | length }} site-to-site VPN tunnels successfully"
|
||||
when: sophos_site_to_site_vpns is defined and sophos_site_to_site_vpns | length > 0
|
||||
tags: ['always']
|
||||
Reference in New Issue
Block a user