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