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