openwrt/image: proper fix for empty directories in mixins
[noc.git] / ansible / roles / openwrt / image / tasks / prepare.yml
1 ---
2 - name: Create temporary build directory
3   tempfile:
4     state: directory
5   register: tmpdir
6
7 - name: set variables needed to build images
8   set_fact:
9     openwrt_imgbuilder_dir:   "{{ tmpdir.path }}"
10     openwrt_imgbuilder_files: "{{ tmpdir.path }}/files"
11
12 - name: Create the download directory
13   file:
14     path: "{{ openwrt_download_dir }}/dl/{{ openwrt_arch }}"
15     state: directory
16     mode: '0755'
17
18 - name: Create the directories for mixins
19   file:
20     path: "{{ item }}"
21     state: directory
22     mode: '0755'
23   loop: "{{ directories | flatten | unique | map('regex_replace', '^', openwrt_imgbuilder_files) | list }}"
24   vars:
25     directories:
26       - "/etc/config"
27       - "{{ openwrt_mixin | map('dirname') | list }}"
28       - "{{ openwrt_mixin | openwrt_mixin_type('directory') | map(attribute='key') | list }}"
29
30 - name: Create symlinks
31   file:
32     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
33     src: "{{ item.value.link }}"
34     force: yes
35     follow: no
36     state: link
37   loop: "{{ openwrt_mixin | openwrt_mixin_type('link') }}"
38   loop_control:
39     label: "{{ item.key }}"
40
41 - name: Copy mixins in place (from file)
42   copy:
43     src: "{{ item.value.file }}"
44     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
45     mode: "{{ item.value.mode | default('0644') }}"
46   loop: "{{ openwrt_mixin | openwrt_mixin_type('file') }}"
47   loop_control:
48     label: "{{ item.key }}"
49
50 - name: Copy mixins in place (from content)
51   copy:
52     content: "{{ item.value.content }}"
53     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
54     mode: "{{ item.value.mode | default('0644') }}"
55   loop: "{{ openwrt_mixin | openwrt_mixin_type('content') }}"
56   loop_control:
57     label: "{{ item.key }}"
58
59 - name: Generate /etc/fstab
60   mount:
61     fstab: "{{ openwrt_imgbuilder_files }}/etc/fstab"
62     state: present
63     src: "{{ item.src | default(omit) }}"
64     path: "{{ item.path | default(omit) }}"
65     fstype: "{{ item.fstype | default(omit) }}"
66     opts: "{{ item.opts | default(omit) }}"
67     boot: "{{ item.boot | default(omit) }}"
68     dump: "{{ item.dump | default(omit) }}"
69     passno: "{{ item.passno | default(omit) }}"
70   when: openwrt_mounts is defined
71   with_items: "{{ openwrt_mounts }}"
72   loop_control:
73     label: "{{ item.path }}"
74
75
76 - name: Create UCI configuration files
77   template:
78     src: uci.j2
79     dest: "{{ openwrt_imgbuilder_files }}/etc/config/{{ item.key }}"
80     mode: 0644
81     trim_blocks: yes
82 #   force: no  ## TODO: fail when overwriting a file
83   with_dict: "{{ openwrt_uci }}"
84   loop_control:
85     label: "{{ item.key }}"
86
87 - name: Create /etc/passwd
88   template:
89     src: passwd.j2
90     dest: "{{ openwrt_imgbuilder_files }}/etc/passwd"
91     mode: 0644
92     trim_blocks: yes
93   when: openwrt_users is defined
94
95 - name: Create /etc/group
96   template:
97     src: group.j2
98     dest: "{{ openwrt_imgbuilder_files }}/etc/group"
99     mode: 0644
100     trim_blocks: yes
101   when: openwrt_groups is defined or openwrt_users is defined
102
103 - name: extract image builder tarball
104   unarchive:
105     copy: False
106     src:  "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}"
107     dest: "{{ openwrt_imgbuilder_dir }}"
108
109 - name: Symlink the cache repository
110   file:
111     state: link
112     src: "{{ openwrt_download_dir }}/dl/{{ openwrt_arch }}"
113     path: "{{ openwrt_imgbuilder_dir }}/{{ openwrt_tarball_basename }}/dl"