From f82eed7c91f66ebed66bfcde8bb4f17647ab5ff0 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Mon, 13 Jul 2015 14:21:28 +0200 Subject: [PATCH] Adding network role for setting network and dhcp settings via uci --- roles/network/README.md | 53 +++++++++++++++++++++++++++++++++ roles/network/defaults/main.yml | 20 +++++++++++++ roles/network/handlers/main.yml | 14 +++++++++ roles/network/meta/main.yml | 15 ++++++++++ roles/network/tasks/main.yml | 20 +++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 roles/network/README.md create mode 100644 roles/network/defaults/main.yml create mode 100644 roles/network/handlers/main.yml create mode 100644 roles/network/meta/main.yml create mode 100644 roles/network/tasks/main.yml diff --git a/roles/network/README.md b/roles/network/README.md new file mode 100644 index 0000000..d3e3d3a --- /dev/null +++ b/roles/network/README.md @@ -0,0 +1,53 @@ +openwrt-network +================ + +network (and dhcp) config of your openwrt system. +compare: [http://wiki.openwrt.org/doc/uci/network] and +[http://wiki.openwrt.org/doc/uci/dhcp] + +Role Variables +-------------- + +a bunch of per interface settings are all nested in a dict +`network` and another `dhcp` one. the layout is a bit weird because +i use with_subelements. look at the defaults and tasks directory. +if you have a suggestion for how to do it more effectively without +duplication, let me know! + +you may want to consider `hash_behaviour=merge` in your ansible.cfg + +Dependencies +------------ + +[lefant.openwrt-uci] + +Example Playbook +---------------- + +[https://github.com/lefant/ansible-openwrt/blob/master/openwrt.yml] + +Requirements +------------ + +must be kept minimal as this is supposed to run on openwrt embedded +systems. in particular we try get by with plain POSIX shell, using +neither python nor bash in any way. lua could be an option as that +seems to be the openwrt scripting language of choice. + +License +------- + +BSD + +Author Information +------------------ + +Jan Wagner [http://blog.waja.info/] + + + +[https://github.com/lefant/ansible-openwrt/blob/master/openwrt.yml]: https://github.com/lefant/ansible-openwrt/blob/master/openwrt.yml +[http://wiki.openwrt.org/doc/uci/network]: http://wiki.openwrt.org/doc/uci/network +[http://wiki.openwrt.org/doc/uci/dhcp]: http://wiki.openwrt.org/doc/uci/dhcp +[lefant.openwrt-uci]: https://galaxy.ansible.com/list#/roles/1645 +[http://e.lefant.net/]: http://e.lefant.net/ diff --git a/roles/network/defaults/main.yml b/roles/network/defaults/main.yml new file mode 100644 index 0000000..477a61c --- /dev/null +++ b/roles/network/defaults/main.yml @@ -0,0 +1,20 @@ +--- +# defaults file for openwrt-network +network: + - key: ipaddr + value: 192.168.1.1 + ifaces: [lan] + - key: netmask + value: 255.255.255.0 + ifaces: [lan] + - key: gateway + value: "" + ifaces: [lan] + - key: dns + value: "" + ifaces: [lan] + +dhcp: + - key: ignore + value: "" + ifaces: [lan] diff --git a/roles/network/handlers/main.yml b/roles/network/handlers/main.yml new file mode 100644 index 0000000..eff49b9 --- /dev/null +++ b/roles/network/handlers/main.yml @@ -0,0 +1,14 @@ +--- +# handlers file for openwrt-network +- name: reload network + raw: /etc/init.d/network reload + +- name: restart network + raw: /etc/init.d/network restart + +- name: reload dhcp + raw: /etc/init.d/dnsmasq reload + +- name: restart dhcp + raw: /etc/init.d/dnsmasq restart + diff --git a/roles/network/meta/main.yml b/roles/network/meta/main.yml new file mode 100644 index 0000000..df3798d --- /dev/null +++ b/roles/network/meta/main.yml @@ -0,0 +1,15 @@ +--- +galaxy_info: + author: Jan Wagner + description: network config of your openwrt system. + license: BSD + min_ansible_version: 1.7 + platforms: [] + # - Openwrt + # versions: + # - 14.07 + categories: + - system + - network +dependencies: + - { role: lefant.openwrt-uci } diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml new file mode 100644 index 0000000..d9774c5 --- /dev/null +++ b/roles/network/tasks/main.yml @@ -0,0 +1,20 @@ +--- +# tasks file for openwrt-network +- name: apply network uci settings + uci: command=set key="network.{{ item.1 }}.{{ item.0.key }}" value="{{ item.0.value }}" + with_subelements: + - network + - ifaces + notify: + - uci commit + - restart network + +- name: apply dhcp uci settings + uci: command=set key="dhcp.{{ item.1 }}.{{ item.0.key }}" value="{{ item.0.value }}" + with_subelements: + - dhcp + - ifaces + notify: + - uci commit + - restart dhcp +