openwrt/image: proper fix for empty directories in mixins
[noc.git] / ansible / roles / openwrt / image / tasks / prepare.yml
index ff6a613..f3eafc7 100644 (file)
@@ -4,50 +4,55 @@
     state: directory
   register: tmpdir
 
-- set_fact:
+- name: set variables needed to build images
+  set_fact:
     openwrt_imgbuilder_dir:   "{{ tmpdir.path }}"
     openwrt_imgbuilder_files: "{{ tmpdir.path }}/files"
 
+- name: Create the download directory
+  file:
+    path: "{{ openwrt_download_dir }}/dl/{{ openwrt_arch }}"
+    state: directory
+    mode: '0755'
+
 - name: Create the directories for mixins
   file:
     path: "{{ item }}"
     state: directory
     mode: '0755'
-  with_items:
-    - "{{ openwrt_download_dir }}/dl/{{ openwrt_arch }}"
-    - "{{ openwrt_imgbuilder_files }}/etc/config"
-    - "{{ openwrt_mixin | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}"
-
+  loop: "{{ directories | flatten | unique | map('regex_replace', '^', openwrt_imgbuilder_files) | list }}"
+  vars:
+    directories:
+      - "/etc/config"
+      - "{{ openwrt_mixin | map('dirname') | list }}"
+      - "{{ openwrt_mixin | openwrt_mixin_type('directory') | map(attribute='key') | list }}"
 
-- name: Copy mixins in place [1/3]
+- name: Create symlinks
   file:
     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
     src: "{{ item.value.link }}"
     force: yes
     follow: no
     state: link
-  with_dict: "{{ openwrt_mixin }}"
-  when: '"link" in item.value'
+  loop: "{{ openwrt_mixin | openwrt_mixin_type('link') }}"
   loop_control:
     label: "{{ item.key }}"
 
-- name: Copy mixins in place [2/3]
+- name: Copy mixins in place (from file)
   copy:
     src: "{{ item.value.file }}"
     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
     mode: "{{ item.value.mode | default('0644') }}"
-  with_dict: "{{ openwrt_mixin }}"
-  when: '"file" in item.value'
+  loop: "{{ openwrt_mixin | openwrt_mixin_type('file') }}"
   loop_control:
     label: "{{ item.key }}"
 
-- name: Copy mixins in place [3/3]
+- name: Copy mixins in place (from content)
   copy:
     content: "{{ item.value.content }}"
     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
     mode: "{{ item.value.mode | default('0644') }}"
-  with_dict: "{{ openwrt_mixin }}"
-  when: '"content" in item.value'
+  loop: "{{ openwrt_mixin | openwrt_mixin_type('content') }}"
   loop_control:
     label: "{{ item.key }}"
 
     trim_blocks: yes
   when: openwrt_groups is defined or openwrt_users is defined
 
-- unarchive:
+- name: extract image builder tarball
+  unarchive:
     copy: False
     src:  "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}"
     dest: "{{ openwrt_imgbuilder_dir }}"