Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmosified committed May 3, 2023
2 parents da56a2c + 92f8e6c commit d698f76
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The following modules are currently available:
* [pfsense_openvpn_server](https://github.com/pfsensible/core/wiki/pfsense_openvpn_server) for OpenVPN server configuration
* [pfsense_nat_outbound](https://github.com/pfsensible/core/wiki/pfsense_nat_outbound) for outbound NAT (SNAT) rules
* [pfsense_nat_port_forward](https://github.com/pfsensible/core/wiki/pfsense_nat_port_forward) for port forwarding NAT (DNAT) rules
* [pfsense_rewrite_config](https://github.com/pfsensible/core/wiki/pfsense_rewrite_config) to rewrite config.xml
* [pfsense_route](https://github.com/pfsensible/core/wiki/pfsense_route) for routes
* [pfsense_rule](https://github.com/pfsensible/core/wiki/pfsense_rule) for firewall rules
* [pfsense_rule_separator](https://github.com/pfsensible/core/wiki/pfsense_rule_separator) for firewall rule separators
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace: pfsensible
name: core

# The version of the collection. Must be compatible with semantic versioning
version: 0.5.2
version: 0.5.3

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
89 changes: 89 additions & 0 deletions plugins/modules/pfsense_rewrite_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2023, Orion Poplawski <orion@nwra.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type


ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}

DOCUMENTATION = """
---
module: pfsense_rewrite_config
version_added: 0.5.3
author: Orion Poplawski (@opoplawski)
short_description: Rewrite pfSense config.xml
description:
- Rewrites pfSense's config.xml using native tools to reproduce formatting.
notes:
"""

EXAMPLES = """
- name: Rewrite pfSense config.xml
pfsense_rewrite_config:
"""

RETURN = """
"""

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.pfsensible.core.plugins.module_utils.module_base import PFSenseModuleBase


REWRITE_CONFIG_ARGUMENT_SPEC = dict()


class PFSenseRewriteConfigModule(PFSenseModuleBase):
""" module managing pfsense routes """

@staticmethod
def get_argument_spec():
""" return argument spec """
return REWRITE_CONFIG_ARGUMENT_SPEC

##############################
# init
#
def __init__(self, module, pfsense=None):
super(PFSenseRewriteConfigModule, self).__init__(module, pfsense)
self.name = "pfsense_rewrite_config"
self.result['changed'] = True

##############################
# run
#
def commit_changes(self):
""" apply changes and exit module """
self.result['stdout'] = ''
self.result['stderr'] = ''
if self.result['changed'] and not self.module.check_mode:
(dummy, self.result['stdout'], self.result['stderr']) = self._update()

self.module.exit_json(**self.result)

def _update(self):
""" make the target pfsense rewrite the config.xml file """

cmd = '''
parse_config(true);
write_config('pfsense_rewrite_config');'''

return self.pfsense.phpshell(cmd)


def main():
module = AnsibleModule(
argument_spec=REWRITE_CONFIG_ARGUMENT_SPEC,
supports_check_mode=True)

pfmodule = PFSenseRewriteConfigModule(module)
pfmodule.commit_changes()


if __name__ == '__main__':
main()

0 comments on commit d698f76

Please sign in to comment.