-
Notifications
You must be signed in to change notification settings - Fork 0
/
ans-pl-makepxeserv_v8.yml
267 lines (234 loc) · 10 KB
/
ans-pl-makepxeserv_v8.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# It's playbook designed for use with Debian v11
# It's make some PXE server for network install the Debian OS, distributive Debian must be inserted in to CD tray
# 2022-04-08
#
#
---
- hosts: localhost
become: yes #all tasks run from root user
become_method: enable
vars:
file_name_config_dhcpd: /etc/dhcp/dhcpd.conf #Config file thet will be changed
file_name_config_ipxe: menu.ipxe #file name config iPXE bootloader (menu)
directory_root_pxeserver: /srv/tftp #Path to boot files and default root directory for all servers (ftp,tftp, nfs and other)
directory_for_distr: /srv/tftp/iso #folder for download some iso files
directory_for_bootloader: /srv/tftp/bootloader #directry for bootloader save
directory_for_repository: /srv/tftp/repository #directory where will be mount iso files and save some kernel linux for booting
directory_all_list:
- "{{ directory_root_pxeserver }}"
- "{{ directory_for_distr }}"
- "{{ directory_for_bootloader }}"
- "{{ directory_for_repository }}"
interface_name: ens192 #interface name thet will be use for dhcp server
ip4_address_pxe: 192.168.0.1
net_mask_pxe: 255.255.255.0
ip4_broadcast_pxe: 192.168.0.255
gateway_default_pxe: 192.168.0.1
dns_default_pxe: 192.168.0.1
dhcp_range: 192.168.0.100 192.168.0.200
dhcp_subnet: 192.168.0.0
domain_name_pxe: pxeserver.lan
name_reposytory_server: mirror.yandex.ru
type_of_version: stable
type_of_arhitection: i386
list_of_nessary_packages:
- isc-dhcp-server
- vsftpd
- tftpd-hpa
- rsync #need for work ansible module "sync" - for copy files
- ipxe #distr of bootloader ipxe
- apache2 #for make are HTTP file server, for loading ISO over Sun module in ipxe
url_iso_file:
- https://mirror.yandex.ru/debian-cd/current/i386/iso-dvd/debian-11.3.0-i386-DVD-1.iso
- https://mirror.yandex.ru/astra/stable/orel/iso/orel-2.12.43-14.09.2021_10.29.iso
- https://mirror.yandex.ru/debian-cd/current/i386/iso-cd/debian-11.3.0-i386-netinst.iso
menu_item_title:
- Debian x86, for old PC (full DVD iso)
- AstraLinux Orel x64 (full DVD iso)
- Debian x86 NetInstall (need acces to repository)
tasks:
- name: Install the necessary APPs
apt:
cache_valid_time: 28800
update_cache: yes
pkg: '{{ list_of_nessary_packages }}'
state: present
- name: Configure network Interface for PXE server, interface = "{{ interface_name }}"
blockinfile:
path: /etc/network/interfaces
insertafter: EOF
state: present
block: |
allow-hotplug {{ interface_name }}
iface {{ interface_name }} inet static
address {{ ip4_address_pxe }}
netmask {{ net_mask_pxe }}
network {{ dhcp_subnet }}
gateway {{ gateway_default_pxe }}
- name: Restart network interface (for apply static address)
service:
name: networking
state: restarted
#for debug
- name: Get current ipv4 address from {{ interface_name }}
shell:
cmd: ip address
- name: Creates all needs directory for PXE Server
file:
path: '{{ item }}'
state: directory
with_items: '{{ directory_all_list }}'
- name: Set \# Comment at all lines in file DHCP server "{{ file_name_config_dhcpd }}"
replace:
path: "{{ file_name_config_dhcpd }}"
regexp: '^(.+)$' #regexp = for any new line with any symbol by the end of line
replace: '# \1'
backup: yes
- name: Making Config File DHCP server- "{{ file_name_config_dhcpd }}"
blockinfile:
path: "{{ file_name_config_dhcpd }}"
backup: yes
insertafter: EOF
block: |
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
option domain-name "{{ domain_name_pxe }}";
allow booting;
allow bootp;
# Main option, this option says to Client where TFTP server based
next-server {{ ip4_address_pxe }} ;
#
option client-architecture code 93 = unsigned integer 16;
subnet {{ dhcp_subnet }} netmask {{ net_mask_pxe }} {
range {{ dhcp_range }};
option domain-name-servers {{ dns_default_pxe }}, 8.8.8.8;
option broadcast-address {{ ip4_broadcast_pxe }};
option routers {{ gateway_default_pxe }};
option subnet-mask {{ net_mask_pxe }};
if exists user-class and ( option user-class = "iPXE" ) {
filename "http://{{ ip4_address_pxe }}/{{ directory_for_bootloader | basename }}/{{ file_name_config_ipxe }}";
} elsif option client-architecture = 00:00 {
filename "{{ directory_for_bootloader | basename }}/undionly.kpxe";
} else {
filename "{{ directory_for_bootloader | basename }}/ipxe.efi";
}
}
- name: Modify config of isc-dhcp-server /etc/default/isc-dhcp-server
lineinfile:
path: /etc/default/isc-dhcp-server
regexp: '^INTERFACESv4=""'
line: 'INTERFACESv4="{{ interface_name }}"'
backup: yes
- name: Remove old config file for iPXE, if they exist {{ directory_for_bootloader }}{{ file_name_config_ipxe }}
file:
path: "{{ directory_for_bootloader }}/{{ file_name_config_ipxe }}"
state: absent
- name: Making Config File for iPXE"
blockinfile:
path: "{{ directory_for_bootloader }}/{{ file_name_config_ipxe }}"
create: yes
mode: 01777
marker: ""
backup: no
insertafter: EOF
block: |
#!ipxe
:start
menu iPXE boot menu
########################## Main Menu ##########################
item --gap Function of iPXE
item reboot Reboot system
item config Config iPXE and view system details
item shell Enter to iPXE command shell
item
########################## Menu to load ISO file ##########################
item --gap System to boot
#place_for_add_menu_item
#
choose target && goto ${target}
#
#place_for_add_script
#
:reboot
reboot
#
:config
config
goto start
#
:shell
echo Type 'exit' to get the back to the menu
shell
set menu-timeout 0
set submenu-timeout 0
goto start
- name: Clear blank lines in Menu file - menu MUST start by line \#!pxe
lineinfile :
path: "{{ directory_for_bootloader }}/{{ file_name_config_ipxe }}"
state: absent
regexp: '^$'
- name: Copy EFI Bootloaders to the PXE boot directory - {{ directory_for_bootloader }}
file:
src: "/boot/{{ item }}"
dest: "{{ directory_for_bootloader }}/{{ item }}"
state: hard
with_items:
- ipxe.lkrn
- ipxe.efi
- name: Copy BIOS Bootloader to the PXE boot directory - {{ directory_for_bootloader }}
file:
src: "/usr/lib/ipxe/undionly.kpxe"
dest: "{{ directory_for_bootloader }}/undionly.kpxe"
state: hard
- name: 01 Configure Apache2 server - for HTTP File server
lineinfile:
backup: yes
path: /etc/apache2/apache2.conf
regexp: '^<Directory /var/www/>'
line: '<Directory {{ directory_root_pxeserver }}/>'
backup: yes
- name: 02 Configure Apache2 server - for HTTP File server
lineinfile:
backup: yes
path: /etc/apache2/sites-enabled/000-default.conf
regexp: '^\tDocumentRoot /var/www/html'
line: "\tDocumentRoot {{ directory_root_pxeserver }}/" #only double quotes allow use tab symbol - \t
backup: yes
- name: Restart Apache2 service
service:
name: apache2
state: restarted
- name: Restart DHCP service
service:
name: isc-dhcp-server
state: restarted
- name: Download ISO # Ansible have the bug, need add manual check for exist downloading file - https://translated.turbopages.org/proxy_u/en-ru.ru.f0df2e4e-62755f7e-81da6089-74722d776562/https/github.com/ansible/ansible/issues/64016
get_url: # module get_url - have not indication of Download process, this task may be "freez" by long time
url: '{{ item }}'
dest: '{{ directory_for_distr }}/'
when: not ('{{ directory_for_distr }}/{{ item | basename }}') is exists
with_items: '{{ url_iso_file }}'
- name: Modify Bootloader menu - add new item in menu
lineinfile:
path: "{{ directory_for_bootloader }}/{{ file_name_config_ipxe }}"
regexp: '^#place_for_add_menu_item'
line: |
item {{ item.0 | basename | regex_replace("\\.", "") }} {{ item.1 }}
#
#place_for_add_menu_item
with_together:
- "{{ url_iso_file }}"
- "{{ menu_item_title }}"
- name: Modify Bootloader menu - add new script to load iso file
lineinfile:
path: '{{ directory_for_bootloader }}/{{ file_name_config_ipxe }}'
regexp: '^#place_for_add_script'
line: |
:{{ item | basename | regex_replace("\\.", "") }}
sanboot --no-describe http://{{ ip4_address_pxe }}/{{ directory_for_distr | basename }}/{{ item | basename }}
boot
goto start
#
#place_for_add_script
with_items: '{{ url_iso_file }}'