roles/openwrt-image: Natively support UCI configuration
[noc.git] / ansible / roles / openwrt-image / tasks / prepare.yml
index 30cd32b..b697e39 100644 (file)
     path: "{{ item }}"
     state: directory
   with_items:
-    - "{{ openwrt_imgbuilder_files }}"
-    - "{{ openwrt_mixin.files | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}"
-    - "{{ openwrt_mixin.content | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}"
+    - "{{ 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.value }}"
+    src: "{{ item.file }}"
     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
-  with_dict: "{{ openwrt_mixin.files }}"
+    mode: "{{ item.mode | default(0644) }}"
+  with_dict: "{{ openwrt_mixin }}"
+  when: '"file" in item'
   loop_control:
     label: "{{ item.key }}"
 
   copy:
     content: "{{ item.value }}"
     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
-  with_dict: "{{ openwrt_mixin.content }}"
+    mode: "{{ item.mode | default(0644) }}"
+  with_dict: "{{ openwrt_mixin }}"
+  when: '"content" in item'
   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