roles/openwrt-image: Natively support UCI configuration
authornicoo <nicoo@realraum.at>
Wed, 16 May 2018 19:32:27 +0000 (21:32 +0200)
committernicoo <nicoo@realraum.at>
Wed, 16 May 2018 19:37:23 +0000 (21:37 +0200)
ansible/roles/openwrt-image/tasks/prepare.yml
ansible/roles/openwrt-image/uci.j2 [new file with mode: 0644]
ansible/tuer.yml

index 29e24cd..b697e39 100644 (file)
     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 }}"
   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 (file)
index 0000000..78b3468
--- /dev/null
@@ -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 %}
index 1ed9f12..29af04f 100644 (file)
             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