-
Notifications
You must be signed in to change notification settings - Fork 9
Draft: Implement faster xml_template mode using NetBox inventory #61
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
base: main
Are you sure you want to change the base?
Draft: Implement faster xml_template mode using NetBox inventory #61
Conversation
Hello @ypid Thank you for your interest in improving this role. I can vaguely remember your interesting PR in the original naturalis repo of this playbook. Well, your idea sounds quite interesting. So I am interested in speeding it up ... I was thinking about some changes too, using jinja templates or the opnsense api ... Well, the templates have their own order of elements and opnsense has its own, so I have refrained from going this way, as I considered this a far to complex and error prone process. I think with jinja templates the config will be often have changes in the structure without real changes to the content. Using the opnsense api ... a long and winding road to that goal ... Well ... much speak about it ... just put it in a nutshell: I see the need for a different implementation / improvements, have some ideas but see some issues ... I have only taken a rough look at, do not yet see through all the changes, but I am willing to try it out ... but I have to admit our/my time resources are very limited, so I can not promise when I can have a first test run. I can see you have addressed already some issue regarding #12 Until then, I would be very happy if you can document the changes, so we can test the new features easily. Especially: will there be some way to convert existing VARs driving the current playbook to the netbox inventory? Using FQCN notation for the ansible modules would be great too (you can do this very fast using https://github.com/zerwes/ansible-fqcn-converter) and usning ansible-lint for the changes too. Greetings |
76a723b
to
ec898d0
Compare
I am currently on vacation and will take care of it when I get back ... |
Enjoy! I still have quite some work to do on this pull request (update the template, see if I can make NetBox optional, write basic docs). Thanks already for your long replay and that you like the idea in general. |
…sa-Luxemburgstiftung-Berlin#40 * A concept how users can make changes to the template and still receive updates to it is not clear yet. For now it is expected that you copy the template into the git repo where your Ansible inventory lives and make changes there. * Set the device file (fetched) to read only to prevent user edits A common way to develop the Jinja2 template is to configure a OPNsense, fetch the config and then diff it (using git). Then you might copy parts over to the template. When you have multiple files (all XML), you might confuse one for the other. Setting all such files that are not the template (which is meant to be edited) to read only helps to notice such mistakes earlier. * The file copyright style complies with https://reuse.software/
`//opnsense/dnsmasq/custom_options` might be templated not not contained in the config pulled from the target.
ec898d0
to
087ebc5
Compare
I have played with this more and there is also another route I will evaluate. How to Generate Device Configurations with NetBox. So the heavy lifting of generating the
PS: This repetitive objects in NetBox like IP addresses, VLANs, CARP should itself managed by something like Terraform modules to lifecycle management. |
When restoring the config to a freshly installed system, the packages are not automatically installed. Instead, packages in the config that are not installed are shown as missing in the GUI and it is offered to install them. This commit automates this.
Helps with debugging.
=== Do not change lines below === { "chain": [], "cmd": "2to3 --write xmlfile.py", "exit": 0, "extra_inputs": [], "inputs": [], "outputs": [], "pwd": "lookup_plugins" } ^^^ Do not change lines above ^^^
087ebc5
to
42aff79
Compare
I implemented a different way how to put together the XML that you might be interested in. The main reason is scalability, especially when you want to configure many VLANs, interfaces and so on, running hundreds or thousands of Ansible tasks was slow, at least when I wrote the
xml_template
mode in 2021-05.With this mode, I am able to generate my fw config in 30 seconds.
Another interesting feature this offers: The generated config can include parts of the device config. It works like this:
{{ lookup("xmlfile", local_config_path_fetch, xpath="//opnsense/filter/rule[not(contains(descr, 'Ansible managed.'))]") }}
It is currently a draft. If you are interested, I can get it polished, update the template based on my private template which is updated to the latest OPNsense release (24.7.x). What do you say?
I had this PR open against https://github.com/naturalis/ansible-opnsense but it was deleted sadly.