-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/latest' into latest
- Loading branch information
Showing
14 changed files
with
255 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.api import \ | ||
Session | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.helper.main import \ | ||
is_ip, validate_port | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.cls import GeneralModule | ||
|
||
|
||
class ControlAgent(GeneralModule): | ||
FIELD_ID = 'ip' | ||
CMDS = { | ||
'set': 'set', | ||
'search': 'get', | ||
} | ||
API_KEY_PATH = 'ctrlagent.general' | ||
API_KEY_PATH_REQ = API_KEY_PATH | ||
API_MOD = 'kea' | ||
API_CONT = 'ctrl_agent' | ||
API_CONT_REL = 'service' | ||
API_CMD_REL = 'reconfigure' | ||
FIELDS_CHANGE = [ | ||
'enabled', 'http_host', 'http_port' | ||
] | ||
FIELDS_ALL = [*FIELDS_CHANGE] | ||
FIELDS_TYPING = { | ||
'bool': ['enabled'], | ||
'int': ['http_port'], | ||
} | ||
INT_VALIDATIONS = { | ||
'http_port': {'min': 1, 'max': 65535}, | ||
} | ||
|
||
def __init__(self, module: AnsibleModule, result: dict, session: Session = None): | ||
GeneralModule.__init__(self=self, m=module, r=result, s=session) | ||
|
||
def check(self) -> None: | ||
if not validate_port(module=self.m, port=self.p['http_port']): | ||
self.m.fail_json('The provided port is invalid!') | ||
|
||
if not is_ip(self.p['http_host']): | ||
self.m.fail_json('The provided IP is invalid!') | ||
|
||
super().check() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright: (C) 2024, AnsibleGuy <[email protected]> | ||
# GNU General Public License v3.0+ (see https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
# see: https://docs.opnsense.org/development/api/plugins/wireguard.html | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.handler import \ | ||
module_dependency_error, MODULE_EXCEPTIONS | ||
|
||
|
||
try: | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.helper.wrapper import module_wrapper | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.defaults.main import \ | ||
OPN_MOD_ARGS, EN_ONLY_MOD_ARG, RELOAD_MOD_ARG | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.main.dhcp_controlagent import ControlAgent | ||
|
||
except MODULE_EXCEPTIONS: | ||
module_dependency_error() | ||
|
||
|
||
# DOCUMENTATION = 'https://opnsense.ansibleguy.net/en/latest/modules/dhcp.html' | ||
# EXAMPLES = 'https://opnsense.ansibleguy.net/en/latest/modules/dhcp.html' | ||
|
||
|
||
def run_module(): | ||
module_args = dict( | ||
http_port=dict( | ||
type='int', required=False, default=8000, | ||
description='Portnumber to use for the RESTful interface' | ||
), | ||
http_host=dict( | ||
type='str', required=False, default='127.0.0.1', aliases=['host'], | ||
description='Address on which the RESTful interface should be available' | ||
), | ||
**EN_ONLY_MOD_ARG, | ||
**OPN_MOD_ARGS, | ||
**RELOAD_MOD_ARG, | ||
) | ||
|
||
result = dict( | ||
changed=False, | ||
diff={ | ||
'before': {}, | ||
'after': {}, | ||
} | ||
) | ||
|
||
module = AnsibleModule( | ||
argument_spec=module_args, | ||
supports_check_mode=True, | ||
) | ||
|
||
module_wrapper(ControlAgent(module=module, result=result)) | ||
module.exit_json(**result) | ||
|
||
|
||
def main(): | ||
run_module() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# Copyright: (C) 2024, AnsibleGuy <[email protected]> | ||
# GNU General Public License v3.0+ (see https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
# see: https://docs.opnsense.org/development/api/plugins/wireguard.html | ||
# see: https://docs.opnsense.org/development/api/core/kea.html | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
|
@@ -21,8 +21,8 @@ | |
module_dependency_error() | ||
|
||
|
||
# DOCUMENTATION = 'https://opnsense.ansibleguy.net/en/latest/modules/wireguard.html' | ||
# EXAMPLES = 'https://opnsense.ansibleguy.net/en/latest/modules/wireguard.html' | ||
# DOCUMENTATION = 'https://opnsense.ansibleguy.net/en/latest/modules/dhcp.html' | ||
# EXAMPLES = 'https://opnsense.ansibleguy.net/en/latest/modules/dhcp.html' | ||
|
||
|
||
def run_module(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
|
||
- name: Testing DHCP-Controlagent | ||
hosts: localhost | ||
gather_facts: no | ||
module_defaults: | ||
group/ansibleguy.opnsense.all: | ||
firewall: "{{ lookup('ansible.builtin.env', 'TEST_FIREWALL') }}" | ||
api_credential_file: "{{ lookup('ansible.builtin.env', 'TEST_API_KEY') }}" | ||
ssl_verify: false | ||
|
||
tasks: | ||
- name: Configuring | ||
ansibleguy.opnsense.dhcp_controlagent: | ||
enabled: true | ||
register: opn1 | ||
failed_when: > | ||
opn1.failed or | ||
not opn1.changed | ||
- name: Changing | ||
ansibleguy.opnsense.dhcp_controlagent: | ||
enabled: true | ||
http_port: 8082 | ||
http_host: '192.168.0.55' | ||
register: opn5 | ||
failed_when: > | ||
opn5.failed or | ||
not opn5.changed | ||
- name: Disabling 1 | ||
ansibleguy.opnsense.dhcp_controlagent: | ||
enabled: false | ||
http_port: 8082 | ||
http_host: '192.168.0.55' | ||
register: opn2 | ||
failed_when: > | ||
opn2.failed or | ||
not opn2.changed | ||
when: not ansible_check_mode | ||
|
||
- name: Disabling 1 - nothing changed | ||
ansibleguy.opnsense.dhcp_controlagent: | ||
enabled: false | ||
http_port: 8082 | ||
http_host: '192.168.0.55' | ||
register: opn3 | ||
failed_when: > | ||
opn3.failed or | ||
opn3.changed | ||
when: not ansible_check_mode | ||
|
||
- name: Enabling 1 | ||
ansibleguy.opnsense.dhcp_controlagent: | ||
enabled: true | ||
http_port: 8082 | ||
http_host: '192.168.0.55' | ||
register: opn4 | ||
failed_when: > | ||
opn4.failed or | ||
not opn4.changed | ||
when: not ansible_check_mode | ||
|
||
- name: Cleanup | ||
ansibleguy.opnsense.dhcp_controlagent: | ||
enabled: false | ||
http_host: '127.0.0.1' | ||
http_port: 8000 | ||
when: not ansible_check_mode |
Oops, something went wrong.