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