Browse Source

First commit

pull/1/head
Rudi Broekhuizen 2 years ago
parent
commit
e9b875a2f1
14 changed files with 255 additions and 0 deletions
  1. +2
    -0
      defaults/main.yml
  2. +12
    -0
      tasks/alias.yml
  3. +12
    -0
      tasks/dhcpd.yml
  4. +21
    -0
      tasks/dnsserver.yml
  5. +12
    -0
      tasks/filter.yml
  6. +12
    -0
      tasks/gateways.yml
  7. +13
    -0
      tasks/general.yml
  8. +37
    -0
      tasks/group.yml
  9. +12
    -0
      tasks/hasync.yml
  10. +12
    -0
      tasks/interfaces.yml
  11. +74
    -0
      tasks/main.yml
  12. +12
    -0
      tasks/user.yml
  13. +12
    -0
      tasks/virtualip.yml
  14. +12
    -0
      tasks/vlans.yml

+ 2
- 0
defaults/main.yml View File

@ -0,0 +1,2 @@
---
config_path: /conf/config.xml

+ 12
- 0
tasks/alias.yml View File

@ -0,0 +1,12 @@
---
- name: aliases
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/aliases/alias[name/text()="{{ item.0.name }}"]/{{ item.1.key }}
value: "{{ item.1.value }}"
pretty_print: yes
with_subelements:
- "{{ opn_alias | default([]) }}"
- settings
...

+ 12
- 0
tasks/dhcpd.yml View File

@ -0,0 +1,12 @@
---
- name: dhcpd
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/dhcpd/{{ item.0.if }}/{{ item.1.key }}
value: "{{ item.1.value }}"
pretty_print: yes
with_subelements:
- "{{ opn_dhcpd | default([]) }}"
- settings
...

+ 21
- 0
tasks/dnsserver.yml View File

@ -0,0 +1,21 @@
---
- name: Count dnsservers set
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/system/dnsserver
count: yes
register: dnsservercount
- name: Dnsservers
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/system
add_children:
- dnsserver: "{{ item }}"
pretty_print: yes
when: dnsservercount.count == 0
with_items:
"{{ dnsserver }}"
...

+ 12
- 0
tasks/filter.yml View File

@ -0,0 +1,12 @@
---
- name: filters
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/filter/rule[descr/text()="{{ item.0.descr }}"]/{{ item.1.key }}
value: "{{ item.1.value }}"
pretty_print: yes
with_subelements:
- "{{ opn_filter | default([]) }}"
- settings
...

+ 12
- 0
tasks/gateways.yml View File

@ -0,0 +1,12 @@
---
- name: gateways
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/gateways/gateway_item[interface/text()="{{ item.0.interface }}"]/{{ item.1.key }}
value: "{{ item.1.value }}"
pretty_print: yes
with_subelements:
- "{{ opn_gateways }}"
- settings
...

+ 13
- 0
tasks/general.yml View File

@ -0,0 +1,13 @@
---
- name: general
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: "{{ item.0.xpath }}/{{ item.1.key }}"
value: "{{ item.1.value }}"
pretty_print: yes
with_subelements:
- "{{ opn_general }}"
#- "{{ opn_general + opn_hasync | default([]) }}"
- settings
...

+ 37
- 0
tasks/group.yml View File

@ -0,0 +1,37 @@
---
- name: groups
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/system/group[name/text()="{{ item.0.name }}"]/{{ item.1.key }}
value: "{{ item.1.value }}"
pretty_print: yes
when: item.1.key is defined
with_subelements:
- "{{ opn_group }}"
- settings
- name: Count member nodes
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/system/group/member
count: yes
register: membercount
- debug:
var: membercount.count
- name: Add users to groups
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/system/group[name/text()="{{ item.0.name }}"]
add_children:
- member: "{{ item.1.member }}"
pretty_print: yes
when: item.1.member is defined and membercount.count <= 1
with_subelements:
- "{{ opn_group }}"
- settings
...

+ 12
- 0
tasks/hasync.yml View File

@ -0,0 +1,12 @@
---
- name: hasync
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: "/opnsense/hasync/{{ item.1.key }}"
value: "{{ item.1.value }}"
pretty_print: yes
with_subelements:
- "{{ opn_hasync | default([]) }}"
- settings
...

+ 12
- 0
tasks/interfaces.yml View File

@ -0,0 +1,12 @@
---
- name: interfaces
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/interfaces/{{ item.0.if }}/{{ item.1.key }}
value: "{{ item.1.value }}"
pretty_print: yes
with_subelements:
- "{{ opn_interfaces_common + opn_interfaces_specific }}"
- settings
...

+ 74
- 0
tasks/main.yml View File

@ -0,0 +1,74 @@
---
#- name: Download OPNsense XML sample config
# get_url:
# url: https://raw.githubusercontent.com/opnsense/core/master/src/etc/config.xml.sample
# dest: /tmp/config.xml
- name: fetch
fetch:
src: /conf/config.xml
dest: /tmp/config-{{ inventory_hostname }}.xml
flat: yes
backup: yes
- name: dnsserver
include: dnsserver.yml
tags: dnsserver
- name: user
include: user.yml
tags: user
- name: group
include: group.yml
tags: group
- name: general
include: general.yml
tags: general
- name: interfaces
include: interfaces.yml
tags: interfaces
- name: vlans
include: vlans.yml
tags: vlans
- name: virtualip
include: virtualip.yml
tags: virtualip
- name: alias
include: alias.yml
tags: alias
- name: filter
include: filter.yml
tags: filter
- name: gateways
include: gateways.yml
when: prod | default([])
tags: gateways
- name: dhcpd
include: dhcpd.yml
tags: dhcpd
- name: copy
copy:
src: /tmp/config-{{ inventory_hostname }}.xml
dest: /conf/config.xml
backup: yes
register: config
tags: copy
- name: reload
command: "{{ item }}"
with_items:
- configctl service reload all
- configctl webgui restart
when: config.changed
tags: reload
...

+ 12
- 0
tasks/user.yml View File

@ -0,0 +1,12 @@
---
- name: Users
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/system/user[name/text()="{{ item.0.name }}"]/{{ item.1.key }}
value: "{{ item.1.value }}"
pretty_print: yes
with_subelements:
- "{{ opn_user | default([]) }}"
- settings
...

+ 12
- 0
tasks/virtualip.yml View File

@ -0,0 +1,12 @@
---
- name: virtualips
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/virtualip/vip[vhid/text()="{{ item.0.vhid }}"]/{{ item.1.key }}
value: "{{ item.1.value }}"
pretty_print: yes
with_subelements:
- "{{ opn_virtualip | default([]) }}"
- settings
...

+ 12
- 0
tasks/vlans.yml View File

@ -0,0 +1,12 @@
---
- name: vlans
delegate_to: localhost
xml:
path: /tmp/config-{{ inventory_hostname }}.xml
xpath: /opnsense/vlans/vlan[tag/text()="{{ item.0.tag }}"]/{{ item.1.key }}
value: "{{ item.1.value }}"
pretty_print: yes
with_subelements:
- "{{ opn_vlans }}"
- settings
...

Loading…
Cancel
Save