Skip to content

Commit

Permalink
initial version of the system_settings_logging module (#61)
Browse files Browse the repository at this point in the history
* initial version of the system_settings_logging module

---------

Co-authored-by: KiLLuuuhh <[email protected]>
  • Loading branch information
rekup and KiLLuuuhh authored Apr 15, 2024
1 parent 46c27a5 commit 9d15fcd
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 3 deletions.
2 changes: 1 addition & 1 deletion molecule/system_settings_general/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
scenario:
name: system_settings_general
test_sequence:
# - dependency not relevant uless we have requirements
# - dependency not relevant unless we have requirements
- destroy
- syntax
- create
Expand Down
54 changes: 54 additions & 0 deletions molecule/system_settings_logging/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
- name: converge
hosts: all
become: true
tasks:

- name: Converge - Get OPNsense version
ansible.builtin.command: opnsense-version -O
register: opnsense_version_cmd

- name: Converge - Set OPNsense version fact
ansible.builtin.set_fact:
opnsense_version: "{{ opnsense_version_cmd.stdout | from_json }}"

- name: Converge - Set preserve logs
puzzle.opnsense.system_settings_logging:
preserve_logs: 11

- name: Converge - Set max log file size on supported opnsense versions
puzzle.opnsense.system_settings_logging:
max_log_file_size_mb: 15
when: opnsense_version["product_version"] is version('24.1', '>=')

- name: Converge - Set max log file size on unsupported opnsense versions
puzzle.opnsense.system_settings_logging:
max_log_file_size_mb: 15
when: opnsense_version["product_version"] is version('24.1', '<')
register: test_unsupported_max_log_file_size_mb
ignore_errors: yes

- name: Verify that setting max_log_file_size_mb failed to to unsupported OPNsense version
ansible.builtin.assert:
that:
- test_unsupported_max_log_file_size_mb is failed
fail_msg: "Setting max_log_file_size_mb should fail on unsupported OPNsense versions"
success_msg: "Setting max_log_file_size_mb failed as expected due to unsupported OPNsense version"
when: opnsense_version["product_version"] is version('24.1', '<')

# we have no alternative way to compare the values
# other than getting them from the config
# see https://github.com/opnsense/core/blob/24.1/src/opnsense/scripts/syslog/log_archive#L36
- name: Get current config
ansible.builtin.slurp:
src: /conf/config.xml
register: current_config

- name: Compare preserve logs
ansible.builtin.assert:
that: "'<preservelogs>11</preservelogs>' in ( current_config.content | b64decode )"

- name: Compare max log file size
ansible.builtin.assert:
that: "'<maxfilesize>15</maxfilesize>' in ( current_config.content | b64decode )"
when: opnsense_version["product_version"] is version('24.1', '>=')
67 changes: 67 additions & 0 deletions molecule/system_settings_logging/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
scenario:
name: system_settings_logging
test_sequence:
# - dependency not relevant unless we have requirements
- destroy
- syntax
- create
- converge
- idempotence
- verify
- destroy

driver:
name: vagrant
parallel: true

platforms:
- name: "22.7"
hostname: false
box: puzzle/opnsense
box_version: "22.7"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'
- name: "23.1"
box: puzzle/opnsense
hostname: false
box_version: "23.1"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'
- name: "23.7"
box: puzzle/opnsense
hostname: false
box_version: "23.7"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'
- name: "24.1"
box: puzzle/opnsense
hostname: false
box_version: "24.1"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'

provisioner:
name: ansible
env:
ANSIBLE_VERBOSITY: 3
verifier:
name: ansible
options:
become: true
6 changes: 6 additions & 0 deletions molecule/system_settings_logging/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Verify connectivity to server
hosts: all
tasks:
- name: Ping the server
ansible.builtin.ping:
65 changes: 63 additions & 2 deletions plugins/module_utils/module_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,22 @@
"configure_params": ["true"],
},
},
}
},
"system_settings_logging": {
"preserve_logs": "syslog/preservelogs",
# Add other mappings here
"php_requirements": [
"/usr/local/etc/inc/config.inc",
"/usr/local/etc/inc/util.inc",
"/usr/local/etc/inc/system.inc",
],
"configure_functions": {
"system_settings_logging": {
"name": "system_syslog_start",
"configure_params": ["true"],
},
},
},
},
"23.1": {
"system_settings_general": {
Expand Down Expand Up @@ -126,6 +141,21 @@
},
},
},
"system_settings_logging": {
"preserve_logs": "syslog/preservelogs",
# Add other mappings here
"php_requirements": [
"/usr/local/etc/inc/config.inc",
"/usr/local/etc/inc/util.inc",
"/usr/local/etc/inc/system.inc",
],
"configure_functions": {
"system_settings_logging": {
"name": "system_syslog_start",
"configure_params": ["true"],
},
},
},
},
"23.7": {
"system_settings_general": {
Expand Down Expand Up @@ -175,6 +205,21 @@
},
},
},
"system_settings_logging": {
"preserve_logs": "syslog/preservelogs",
# Add other mappings here
"php_requirements": [
"/usr/local/etc/inc/config.inc",
"/usr/local/etc/inc/util.inc",
"/usr/local/etc/inc/system.inc",
],
"configure_functions": {
"system_settings_logging": {
"name": "system_syslog_start",
"configure_params": ["true"],
},
},
},
},
"24.1": {
"system_settings_general": {
Expand Down Expand Up @@ -223,6 +268,22 @@
"configure_params": ["true"],
},
},
}
},
"system_settings_logging": {
"preserve_logs": "syslog/preservelogs",
"max_log_file_size_mb": "syslog/maxfilesize",
# Add other mappings here
"php_requirements": [
"/usr/local/etc/inc/config.inc",
"/usr/local/etc/inc/util.inc",
"/usr/local/etc/inc/system.inc",
],
"configure_functions": {
"system_settings_logging": {
"name": "system_syslog_start",
"configure_params": ["true"],
},
},
},
},
}
2 changes: 2 additions & 0 deletions plugins/modules/system_settings_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

"""system_settings_general module: Module to configure general OPNsense system settings"""

# pylint: disable=duplicate-code
__metaclass__ = type

# https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_documenting.html
# fmt: off
# pylint: disable=duplicate-code
DOCUMENTATION = r'''
---
author:
Expand Down
Loading

0 comments on commit 9d15fcd

Please sign in to comment.