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