-
Notifications
You must be signed in to change notification settings - Fork 1
/
openwrt_imagebuilder.yml
153 lines (139 loc) · 4.76 KB
/
openwrt_imagebuilder.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
- name: Create build container
hosts: sppve
gather_facts: false
vars:
resource_type: ct
# imagebuilder depends on python3-distutils, which removed from ubuntu 24.04 with python 3.12
ct_template: spsrv-proxmox:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst
vmid: 3999
hostname: openwrt-imagebuilder
comment: Temp host for building openwrt image
cores: 4
mem: 2048
disk_size: 10
net_ip: 192.168.10.69
net_vlan: 10
net_gw: 192.168.10.1
net_dns: 192.168.10.1
net_domain: "{{ inventory__homelab_domain }}"
openwrt_version: 23.05.5
openwrt_target: x86/64
openwrt_image_builder: openwrt-imagebuilder-{{ openwrt_version }}-{{ openwrt_target | replace('/','-') }}.Linux-x86_64
openwrt_image_builder_url: https://downloads.openwrt.org/releases/{{ openwrt_version }}/targets/{{ openwrt_target }}/{{ openwrt_image_builder }}.tar.xz
openwrt_image_builder_result: /tmp/{{ openwrt_image_builder }}/bin/targets/x86/64/{{ openwrt_image }}.gz
openwrt_image: openwrt-{{ openwrt_version }}-{{ openwrt_target | replace('/','-') }}-generic-ext4-combined.img
openwrt_image_gz: "{{ openwrt_image }}.gz"
proxmox_template_path: /mnt/pve/spsrv-proxmox/template/qcow2
roles:
- { role: pve_manager }
tasks:
- name: Set vars for another plays on this host
ansible.builtin.set_fact:
vmid: "{{ vmid }}"
openwrt_version: "{{ openwrt_version }}"
openwrt_target: "{{ openwrt_target }}"
openwrt_image_builder: "{{ openwrt_image_builder }}"
openwrt_image_builder_url: "{{ openwrt_image_builder_url }}"
openwrt_image_builder_result: "{{ openwrt_image_builder_result }}"
openwrt_image: "{{ openwrt_image }}"
openwrt_image_gz: "{{ openwrt_image_gz }}"
proxmox_template_path: "{{ proxmox_template_path }}"
- name: Build openwrt image
hosts: openwrt-imagebuilder
gather_facts: false
vars:
pve_host: sppve
tasks:
- name: Copy vars from another host
ansible.builtin.set_fact:
openwrt_image_builder: "{{ hostvars[pve_host].openwrt_image_builder }}"
openwrt_image_builder_url: "{{ hostvars[pve_host].openwrt_image_builder_url }}"
openwrt_image_builder_result: "{{ hostvars[pve_host].openwrt_image_builder_result }}"
- name: Install packages for image builder
ansible.builtin.package:
state: present
name:
- build-essential
- libncurses-dev
- zlib1g-dev
- gawk
- git
- gettext
- libssl-dev
- xsltproc
- rsync
- wget
- unzip
- python3
- python3-distutils
- name: Create user
ansible.builtin.user:
name: build
- name: Download image builder
ansible.builtin.unarchive:
src: "{{ openwrt_image_builder_url }}"
dest: /tmp
remote_src: true
owner: build
group: build
creates: /tmp/{{ openwrt_image_builder }}
# https://openwrt.org/docs/guide-user/installation/openwrt_x86
# https://openwrt.org/docs/guide-user/additional-software/imagebuilder
- name: Build image
community.general.make:
target: image
params:
ROOTFS_PARTSIZE: 240
PACKAGES: >-
-dnsmasq
dnsmasq-full
dnscrypt-proxy2
qemu-ga
luci
luci-ssl
openssh-sftp-server
coreutils-base64
coreutils-sha1sum
python3
nano-full
htop
curl
ss
tcpdump
bind-dig
mtr-json
sing-box
wireguard-tools
luci-proto-wireguard
qrencode
chdir: /tmp/{{ openwrt_image_builder }}
become: true
become_user: build
- name: Copy openwrt image from container to proxmox host
hosts: sppve
gather_facts: false
tasks:
- name: Delete old image
ansible.builtin.file:
dest: "{{ proxmox_template_path }}/{{ openwrt_image }}"
state: absent
- name: Copy compressed image from container
ansible.builtin.command:
cmd: pct pull {{ vmid }} {{ openwrt_image_builder_result }} {{ proxmox_template_path }}/{{ openwrt_image_gz }}
register: _result
failed_when: _result.stderr
changed_when: true
- name: Uncompress image
ansible.builtin.command:
cmd: gunzip {{ openwrt_image_gz }}
chdir: "{{ proxmox_template_path }}"
register: _result
failed_when:
- _result.rc != 0
- ('trailing garbage ignored' not in _result.stderr)
changed_when: true
- name: Destroy build container
ansible.builtin.shell: >
pct stop {{ vmid }} && pct destroy {{ vmid }}
changed_when: true