Skip to content
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

Adding network role for setting network and dhcp settings via uci #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions roles/network/README.md
Original file line number Diff line number Diff line change
@@ -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/
20 changes: 20 additions & 0 deletions roles/network/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -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]
14 changes: 14 additions & 0 deletions roles/network/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -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

15 changes: 15 additions & 0 deletions roles/network/meta/main.yml
Original file line number Diff line number Diff line change
@@ -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 }
20 changes: 20 additions & 0 deletions roles/network/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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