fixup! roles/openwrt-image: Add support for setting file modes
[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   with_items:
15     - "{{ openwrt_imgbuilder_files }}/etc/config"
16     - "{{ openwrt_mixin | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}"
17
18
19 - name: Copy mixins in place [1/2]
20   copy:
21     src: "{{ item.value.file }}"
22     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
23     mode: "{{ item.value.mode | default('0644') }}"
24   with_dict: "{{ openwrt_mixin }}"
25   when: '"file" in item.value'
26   loop_control:
27     label: "{{ item.key }}"
28
29 - name: Copy mixins in place [2/2]
30   copy:
31     content: "{{ item.value.content }}"
32     dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
33     mode: "{{ item.value.mode | default('0644') }}"
34   with_dict: "{{ openwrt_mixin }}"
35   when: '"content" in item.value'
36   loop_control:
37     label: "{{ item.key }}"
38
39 - name: Generate /etc/fstab
40   mount:
41     fstab: "{{ openwrt_imgbuilder_files }}/etc/fstab"
42     state: present
43   args:
44     "{{ item }}"
45   when: openwrt_mounts is defined
46   with_items: "{{ openwrt_mounts }}"
47   loop_control:
48     label: "{{ item.path }}"
49
50 - name: Create UCI configuration files
51   template:
52     src: uci.j2
53     dest: "{{ openwrt_imgbuilder_files }}/etc/config/{{ item.key }}"
54     mode: 0644
55     trim_blocks: yes
56 #   force: no  ## TODO: fail when overwriting a file
57   with_dict: "{{ openwrt_uci }}"
58   loop_control:
59     label: "{{ item.key }}"
60
61 - name: Create /etc/passwd
62   template:
63     src: passwd.j2
64     dest: "{{ openwrt_imgbuilder_files }}/etc/passwd"
65     mode: 0644
66     trim_blocks: yes
67   when: openwrt_users is defined
68
69 - name: Create /etc/group
70   template:
71     src: group.j2
72     dest: "{{ openwrt_imgbuilder_files }}/etc/group"
73     mode: 0644
74     trim_blocks: yes
75   when: openwrt_groups is defined or openwrt_users is defined
76
77 ### TODO: this just hangs?
78 # - unarchive:
79 #     copy: False
80 #     src:  "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}"
81 #     dest: "{{ openwrt_imgbuilder_dir }}"
82
83 - name: Decompress the OpenWrt image builder
84   command: >-
85     tar -xf  "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}"
86     -C   "{{ openwrt_imgbuilder_dir     }}"