Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit of the system_settings_general module #21

Merged
merged 6 commits into from
Dec 29, 2023
Merged

initial commit of the system_settings_general module #21

merged 6 commits into from
Dec 29, 2023

Conversation

rekup
Copy link
Contributor

@rekup rekup commented Sep 17, 2023

  • add diff property to OPNsenseConfig class which returns a dict with the config diff as required by ansible to display diffs using the --diff flag
  • add config_utils which handles the required actions to apply changes in the System -> Settings -> General view
  • add system_settings_general module with the ability to set hostname and domain

⚠️ depends on #39

@DonGiovanni83
Copy link
Contributor

While running the molecule tests in rekup/puzzle.opnsense#1, I noticed that the module fails when the hostname or domain is changed due to a lost connection. I suspect Ansible should wait for the apply -php step to take effect in the background.

Here the error output:

$ molecule test --scenario-name system_settings_general --destroy never 
.........

TASK [Converge - Set a hostname] ***********************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: __init__() missing 1 required positional argument: 'cmd'
fatal: [23.1]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 127.0.0.1 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ik6qcor2/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/modules/system_settings_general.py\", line 168, in main\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ik6qcor2/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/module_utils/system_settings_general_utils.py\", line 67, in apply\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ik6qcor2/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/module_utils/opnsense_utils.py\", line 34, in run_function\r\n  File \"/usr/local/lib/python3.9/subprocess.py\", line 528, in run\r\n    raise CalledProcessError(retcode, process.args,\r\nsubprocess.CalledProcessError: Command '['php', '-r', \"require '/usr/local/etc/inc/config.inc'; require '/usr/local/etc/inc/util.inc'; require '/usr/local/etc/inc/system.inc'; require '/usr/local/etc/inc/interfaces.lib.inc'; require '/usr/local/etc/inc/interfaces.inc'; require '/usr/local/etc/inc/filter.inc'; system_resolver_configure(true);\"]' returned non-zero exit status 255.\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1695227914.2019784-596596-128626050602384/AnsiballZ_system_settings_general.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1695227914.2019784-596596-128626050602384/AnsiballZ_system_settings_general.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1695227914.2019784-596596-128626050602384/AnsiballZ_system_settings_general.py\", line 47, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.puzzle.opnsense.plugins.modules.system_settings_general', init_globals=dict(_module_fqn='ansible_collections.puzzle.opnsense.plugins.modules.system_settings_general', _modlib_path=modlib_path),\r\n  File \"/usr/local/lib/python3.9/runpy.py\", line 225, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/local/lib/python3.9/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/local/lib/python3.9/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ik6qcor2/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/modules/system_settings_general.py\", line 174, in <module>\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ik6qcor2/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/modules/system_settings_general.py\", line 166, in main\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ik6qcor2/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/module_utils/config_utils.py\", line 63, in __exit__\r\nTypeError: __init__() missing 1 required positional argument: 'cmd'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: __init__() missing 1 required positional argument: 'cmd'
fatal: [22.7]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 127.0.0.1 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ec1rhwtw/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/modules/system_settings_general.py\", line 168, in main\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ec1rhwtw/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/module_utils/system_settings_general_utils.py\", line 67, in apply\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ec1rhwtw/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/module_utils/opnsense_utils.py\", line 34, in run_function\r\n  File \"/usr/local/lib/python3.9/subprocess.py\", line 528, in run\r\n    raise CalledProcessError(retcode, process.args,\r\nsubprocess.CalledProcessError: Command '['php', '-r', \"require '/usr/local/etc/inc/config.inc'; require '/usr/local/etc/inc/util.inc'; require '/usr/local/etc/inc/system.inc'; require '/usr/local/etc/inc/interfaces.lib.inc'; require '/usr/local/etc/inc/interfaces.inc'; require '/usr/local/etc/inc/filter.inc'; system_resolver_configure(true);\"]' returned non-zero exit status 255.\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1695227914.1935506-596595-262582080912789/AnsiballZ_system_settings_general.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1695227914.1935506-596595-262582080912789/AnsiballZ_system_settings_general.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1695227914.1935506-596595-262582080912789/AnsiballZ_system_settings_general.py\", line 47, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.puzzle.opnsense.plugins.modules.system_settings_general', init_globals=dict(_module_fqn='ansible_collections.puzzle.opnsense.plugins.modules.system_settings_general', _modlib_path=modlib_path),\r\n  File \"/usr/local/lib/python3.9/runpy.py\", line 225, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/local/lib/python3.9/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/local/lib/python3.9/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ec1rhwtw/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/modules/system_settings_general.py\", line 174, in <module>\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ec1rhwtw/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/modules/system_settings_general.py\", line 166, in main\r\n  File \"/tmp/ansible_puzzle.opnsense.system_settings_general_payload_ec1rhwtw/ansible_puzzle.opnsense.system_settings_general_payload.zip/ansible_collections/puzzle/opnsense/plugins/module_utils/config_utils.py\", line 63, in __exit__\r\nTypeError: __init__() missing 1 required positional argument: 'cmd'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP *********************************************************************
22.7                       : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
23.1                       : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

When running the exact same task again just a few moments later, the playbook runs through without any problems.

@rekup
Copy link
Contributor Author

rekup commented Sep 23, 2023

I was able to reproduce the issue. The problem might be related to the opnsense version. The function system_resolver_configure was called system_resolvconf_generate in earlier versions of opnsense. I will investigate further, but I probably have to implement some kind of version check in the system_settings_general_utils to support multiple opnsense versions

@rekup rekup marked this pull request as ready for review December 29, 2023 11:01
Copy link
Contributor

@KiLLuuuhh KiLLuuuhh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me 👍

@rekup rekup merged commit 167aef7 into puzzle:main Dec 29, 2023
30 checks passed
DonGiovanni83 pushed a commit to DonGiovanni83/puzzle.opnsense that referenced this pull request Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants