--- /dev/null
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+from ansible import errors
+
+
+def openwrt_mixin_type(data, mixin_type):
+ try:
+ return [{'key': x, 'value': data[x]} for x in data if mixin_type in data[x]]
+
+ except Exception as e:
+ raise errors.AnsibleFilterError("openwrt_mixin_type(): %s" % str(e))
+
+
+class FilterModule(object):
+
+ filter_map = {
+ 'openwrt_mixin_type': openwrt_mixin_type,
+ }
+
+ def filters(self):
+ return self.filter_map
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 }}"