some more linter fixes
[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 directories for mixins
13   file:
14     path: "{{ item }}"
15     state: directory
16     mode: '0755'
17   with_items:
18     - "{{ openwrt_download_dir }}/dl/{{ openwrt_arch }}"
19     - "{{ openwrt_imgbuilder_files }}/etc/config"
20     - "{{ openwrt_mixin | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}"
21
22
23 - name: Copy mixins in place [1/2]
24   copy:
25     src: "{{ item.value.file }}"
26     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
27     mode: "{{ item.value.mode | default('0644') }}"
28   with_dict: "{{ openwrt_mixin }}"
29   when: '"file" in item.value'
30   loop_control:
31     label: "{{ item.key }}"
32
33 - name: Copy mixins in place [2/2]
34   copy:
35     content: "{{ item.value.content }}"
36     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
37     mode: "{{ item.value.mode | default('0644') }}"
38   with_dict: "{{ openwrt_mixin }}"
39   when: '"content" in item.value'
40   loop_control:
41     label: "{{ item.key }}"
42
43 - name: Generate /etc/fstab
44   mount:
45     fstab: "{{ openwrt_imgbuilder_files }}/etc/fstab"
46     state: present
47     src: "{{ item.src | default(omit) }}"
48     path: "{{ item.path | default(omit) }}"
49     fstype: "{{ item.fstype | default(omit) }}"
50     opts: "{{ item.opts | default(omit) }}"
51     boot: "{{ item.boot | default(omit) }}"
52     dump: "{{ item.dump | default(omit) }}"
53     passno: "{{ item.passno | default(omit) }}"
54   when: openwrt_mounts is defined
55   with_items: "{{ openwrt_mounts }}"
56   loop_control:
57     label: "{{ item.path }}"
58
59
60 - name: Create UCI configuration files
61   template:
62     src: uci.j2
63     dest: "{{ openwrt_imgbuilder_files }}/etc/config/{{ item.key }}"
64     mode: 0644
65     trim_blocks: yes
66 #   force: no  ## TODO: fail when overwriting a file
67   with_dict: "{{ openwrt_uci }}"
68   loop_control:
69     label: "{{ item.key }}"
70
71 - name: Create /etc/passwd
72   template:
73     src: passwd.j2
74     dest: "{{ openwrt_imgbuilder_files }}/etc/passwd"
75     mode: 0644
76     trim_blocks: yes
77   when: openwrt_users is defined
78
79 - name: Create /etc/group
80   template:
81     src: group.j2
82     dest: "{{ openwrt_imgbuilder_files }}/etc/group"
83     mode: 0644
84     trim_blocks: yes
85   when: openwrt_groups is defined or openwrt_users is defined
86
87 - name: extract image builder tarball
88   unarchive:
89     copy: False
90     src:  "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}"
91     dest: "{{ openwrt_imgbuilder_dir }}"
92
93 - name: Symlink the cache repository
94   file:
95     state: link
96     src: "{{ openwrt_download_dir }}/dl/{{ openwrt_arch }}"
97     path: "{{ openwrt_imgbuilder_dir }}/{{ openwrt_tarball_basename }}/dl"