torwachter: rm d3 key as he does no longer want access as told by ruru. Also better...
[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/3]
24   file:
25     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
26     src: "{{ item.value.link }}"
27     force: yes
28     follow: no
29     state: link
30   with_dict: "{{ openwrt_mixin }}"
31   when: '"link" in item.value'
32   loop_control:
33     label: "{{ item.key }}"
34
35 - name: Copy mixins in place [2/3]
36   copy:
37     src: "{{ item.value.file }}"
38     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
39     mode: "{{ item.value.mode | default('0644') }}"
40   with_dict: "{{ openwrt_mixin }}"
41   when: '"file" in item.value'
42   loop_control:
43     label: "{{ item.key }}"
44
45 - name: Copy mixins in place [3/3]
46   copy:
47     content: "{{ item.value.content }}"
48     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
49     mode: "{{ item.value.mode | default('0644') }}"
50   with_dict: "{{ openwrt_mixin }}"
51   when: '"content" in item.value'
52   loop_control:
53     label: "{{ item.key }}"
54
55 - name: Generate /etc/fstab
56   mount:
57     fstab: "{{ openwrt_imgbuilder_files }}/etc/fstab"
58     state: present
59     src: "{{ item.src | default(omit) }}"
60     path: "{{ item.path | default(omit) }}"
61     fstype: "{{ item.fstype | default(omit) }}"
62     opts: "{{ item.opts | default(omit) }}"
63     boot: "{{ item.boot | default(omit) }}"
64     dump: "{{ item.dump | default(omit) }}"
65     passno: "{{ item.passno | default(omit) }}"
66   when: openwrt_mounts is defined
67   with_items: "{{ openwrt_mounts }}"
68   loop_control:
69     label: "{{ item.path }}"
70
71
72 - name: Create UCI configuration files
73   template:
74     src: uci.j2
75     dest: "{{ openwrt_imgbuilder_files }}/etc/config/{{ item.key }}"
76     mode: 0644
77     trim_blocks: yes
78 #   force: no  ## TODO: fail when overwriting a file
79   with_dict: "{{ openwrt_uci }}"
80   loop_control:
81     label: "{{ item.key }}"
82
83 - name: Create /etc/passwd
84   template:
85     src: passwd.j2
86     dest: "{{ openwrt_imgbuilder_files }}/etc/passwd"
87     mode: 0644
88     trim_blocks: yes
89   when: openwrt_users is defined
90
91 - name: Create /etc/group
92   template:
93     src: group.j2
94     dest: "{{ openwrt_imgbuilder_files }}/etc/group"
95     mode: 0644
96     trim_blocks: yes
97   when: openwrt_groups is defined or openwrt_users is defined
98
99 - name: extract image builder tarball
100   unarchive:
101     copy: False
102     src:  "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}"
103     dest: "{{ openwrt_imgbuilder_dir }}"
104
105 - name: Symlink the cache repository
106   file:
107     state: link
108     src: "{{ openwrt_download_dir }}/dl/{{ openwrt_arch }}"
109     path: "{{ openwrt_imgbuilder_dir }}/{{ openwrt_tarball_basename }}/dl"