53 lines
2.1 KiB
YAML
53 lines
2.1 KiB
YAML
---
|
|
# ============================================================================
|
|
# Configure DHCP Servers
|
|
# ============================================================================
|
|
|
|
- name: Get current DHCP server 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><DHCPServer/></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_dhcp_servers
|
|
no_log: "{{ sophos_no_log_sensitive }}"
|
|
tags: ['dhcp']
|
|
|
|
- name: Parse current DHCP server names
|
|
ansible.builtin.set_fact:
|
|
existing_dhcp_servers: "{{ current_dhcp_servers.content | regex_findall('<Name>(.*?)</Name>') }}"
|
|
tags: ['dhcp']
|
|
|
|
- name: Display existing DHCP servers
|
|
ansible.builtin.debug:
|
|
msg: "Found {{ existing_dhcp_servers | length }} existing DHCP servers: {{ existing_dhcp_servers | join(', ') }}"
|
|
tags: ['dhcp']
|
|
|
|
# Loop through each DHCP server and configure it
|
|
- name: Configure DHCP server {{ 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', 'dhcp_server.json.j2') | urlencode }}"
|
|
status_code: [200, 201]
|
|
timeout: "{{ sophos_api_timeout }}"
|
|
loop: "{{ sophos_dhcp_servers }}"
|
|
loop_control:
|
|
label: "{{ item.name }} ({{ item.interface }})"
|
|
register: dhcp_result
|
|
no_log: "{{ sophos_no_log_sensitive }}"
|
|
changed_when: "'successful' in dhcp_result.content | lower or '200' in dhcp_result.content"
|
|
failed_when: "'error' in dhcp_result.content | lower"
|
|
tags: ['dhcp']
|
|
|
|
- name: Display DHCP server configuration results
|
|
ansible.builtin.debug:
|
|
msg: "Configured {{ sophos_dhcp_servers | length }} DHCP servers successfully"
|
|
tags: ['dhcp']
|