diff --git a/playbooks/opnsense.yml b/playbooks/opnsense.yml new file mode 100644 index 0000000..10b0b53 --- /dev/null +++ b/playbooks/opnsense.yml @@ -0,0 +1,32 @@ +--- +- name: Get info on the existing host entries + hosts: localhost + gather_facts: false + module_defaults: + group/ansibleguy.opnsense.all: + firewall: '{{ lookup("env","OPNSENSE_HOST") }}' + api_key: '{{ lookup("env","OPNSENSE_API_KEY") }}' + api_secret: '{{ lookup("env","OPNSENSE_API_SECRET") }}' + api_port: 8443 + + ansibleguy.opnsense.unbound_host: + match_fields: ['description'] + + ansibleguy.opnsense.list: + target: 'unbound_host' + + tasks: + - name: Listing hosts # noqa args[module] + ansibleguy.opnsense.list: + target: 'unbound_host' + register: existing_entries + + - name: Printing entries + ansible.builtin.debug: + var: existing_entries.data + + - name: Generate csv from template + ansible.builtin.template: + src: ../templates/hosts.j2 + mode: "0644" + dest: "/data/output.csv" diff --git a/rulebooks/netbox_listener.yml b/rulebooks/netbox_listener.yml new file mode 100644 index 0000000..c883dd5 --- /dev/null +++ b/rulebooks/netbox_listener.yml @@ -0,0 +1,25 @@ +--- +- name: Listen for Netbox Events + hosts: all + sources: + - name: Netbox Listener + ansible.eda.webhook: + port: 9102 + host: 0.0.0.0 + rules: + - name: Run Template + condition: + all: + - true + actions: + - print_event: + pretty: true + # - run_job_template: + # name: Demo - Clean Log Directory + # organization: OYS + # job_args: + # extra_vars: + # alertmanager_annotations: "{{ event.alert.annotations }}" + # alertmanager_generator_url: "{{ event.alert.generatorURL }}" + # event_mountpoint: "{{ event.alert.labels.mountpoint }}" + # alertmanager_instance: "{{ event.alert.labels.instance }}" diff --git a/templates/hosts.j2 b/templates/hosts.j2 new file mode 100644 index 0000000..cf155da --- /dev/null +++ b/templates/hosts.j2 @@ -0,0 +1,4 @@ +hostname, domain, description, enabled, mx, mxprio, prio, record_type, server, value, uuid +{% for i in existing_entries.data %} +{{ i.hostname }},{{ i.domain }},{{ i.description }},{{ i.enabled }},{{ i.mx }},{{ i.mxprio }},{{ i.prio }},{{ i.record_type }},{{ i.server }},{{ i.value }},{{ i.uuid }} +{% endfor %} \ No newline at end of file