From f29883b753432c86653691a4e2131dd963633ae6 Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 16 May 2018 21:32:27 +0200 Subject: [PATCH] roles/openwrt-image: Natively support UCI configuration --- ansible/roles/openwrt-image/tasks/prepare.yml | 15 ++++++- ansible/roles/openwrt-image/uci.j2 | 9 ++++ ansible/tuer.yml | 59 +++++++++++++------------ 3 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 ansible/roles/openwrt-image/uci.j2 diff --git a/ansible/roles/openwrt-image/tasks/prepare.yml b/ansible/roles/openwrt-image/tasks/prepare.yml index 29e24cd..b697e39 100644 --- a/ansible/roles/openwrt-image/tasks/prepare.yml +++ b/ansible/roles/openwrt-image/tasks/prepare.yml @@ -12,9 +12,10 @@ path: "{{ item }}" state: directory with_items: - - "{{ openwrt_imgbuilder_files }}" + - "{{ openwrt_imgbuilder_files }}/etc/config" - "{{ openwrt_mixin | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}" + - name: Copy mixins in place [1/2] copy: src: "{{ item.file }}" @@ -35,6 +36,18 @@ loop_control: label: "{{ item.key }}" +- name: Create UCI configuration files + template: + src: uci.j2 + dest: "{{ openwrt_imgbuilder_files }}/etc/config/{{ item.key }}" + mode: 0644 + trim_blocks: yes +# force: no ## TODO: fail when overwriting a file + with_dict: "{{ openwrt_uci }}" + loop_control: + label: "{{ item.key }}" + + ### TODO: this just hangs? # - unarchive: # copy: False diff --git a/ansible/roles/openwrt-image/uci.j2 b/ansible/roles/openwrt-image/uci.j2 new file mode 100644 index 0000000..78b3468 --- /dev/null +++ b/ansible/roles/openwrt-image/uci.j2 @@ -0,0 +1,9 @@ +{{ ansible_managed | comment }} + +{% for section in item.value %} +config {{ section.name }} +{% for option, value in section.options.items() %} + option {{ option }} '{{ value }}' +{% endfor %} + +{% endfor %} diff --git a/ansible/tuer.yml b/ansible/tuer.yml index 1ed9f12..29af04f 100644 --- a/ansible/tuer.yml +++ b/ansible/tuer.yml @@ -76,37 +76,40 @@ mode: 0755 file: "{{ playbook_dir }}/.cache/openwrt/tuer/door_and_sensors/update-keys/update-keys" - /etc/config/network: - content: | - config interface 'loopback' - option ifname 'lo' - option proto 'static' - option ipaddr '127.0.0.1' - option netmask '255.0.0.0' - - config globals 'globals' - option ula_prefix 'fdc9:e01f:83db::/48' - - config interface 'lan' - option ifname 'eth0' - option accept_ra '0' - option proto 'static' - option ipaddr '192.168.33.7' - option netmask '255.255.255.0' - option gateway '192.168.33.1' - option dns '192.168.33.1' - option dns_search 'realraum.at' - - /etc/config/dropbear: - content: | - config dropbear - option PasswordAuth 'off' - option RootPasswordAuth 'off' - option Port '22000' - /etc/dropbear/authorized_keys: mode: 0600 content: |- {% for key in noc_ssh_keys %} {{ key }} {% endfor %} + + openwrt_uci: + network: + - name: globals 'globals' + options: + ula_prefix: fdc9:e01f:83db::/48 + + - name: interface 'loopback' + options: + ifname: lo + proto: static + ipaddr: 127.0.0.1 + netmask: 255.0.0.0 + + - name: interface 'lan' + options: + ifname: eth0 + accept_ra: 0 + proto: static + ipaddr: 192.168.33.7 + netmask: 255.255.255.0 + gateway: 192.168.33.1 + dns: 192.168.33.1 + dns_search: realraum.at + + dropbear: + - name: dropbear + options: + PasswordAuth: off + RootPasswordAuth: off + Port: 22000 -- 1.7.10.4