This repository has been archived by the owner on Apr 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.yml
142 lines (126 loc) · 4.21 KB
/
main.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
---
#This role installs and configures the DHCP server
- name: Install dependencies
package: name={{ item }} state=latest
with_items:
- gcc
- binutils
- make
- perl
- mtools
- mkisofs
- syslinux
become: true
- name: Install liblzma for Ubuntu
package: name={{ item }} state=latest
with_items:
- liblzma-dev
- pxelinux
become: true
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Install xz headers for CentOS
package: name={{ item }} state=latest
with_items:
- xz
- xz-devel
become: true
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
- name: Create pxelinux directory for CentOS
file:
path: /var/lib/tftpboot/pxelinux.cfg
state: directory
group: "{{ lookup('env', 'USER') }}"
owner: "{{ lookup('env', 'USER') }}"
mode: 0777
become: true
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
- name: Create pxelinux directory for Ubuntu
file:
path: /tftpboot/pxelinux.cfg
state: directory
group: "{{ lookup('env', 'USER') }}"
owner: "{{ lookup('env', 'USER') }}"
mode: 0777
become: true
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Install iPXE
git:
repo: http://git.ipxe.org/ipxe.git
dest: "{{playbook_dir}}/ipxe"
- name: Make iPXE
make:
chdir: "{{ playbook_dir }}/ipxe/src"
- name: Copy ipxe.lkrn CentOS
copy:
src: "{{ playbook_dir }}/ipxe/src/bin/ipxe.lkrn"
dest: "/var/lib/tftpboot"
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
- name: Copy ipxe.lkrn for Ubuntu
copy:
src: "{{ playbook_dir }}/ipxe/src/bin/ipxe.lkrn"
dest: "/tftpboot"
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Copy files from syslinux for CentOS
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ lookup('env', 'USER') }}"
group: "{{ lookup('env', 'USER') }}"
mode: 0777
become: true
with_items:
- { src: '/usr/share/syslinux/chain.c32', dest: '/var/lib/tftpboot/chain.c32' }
- { src: '/usr/share/syslinux/mboot.c32', dest: '/var/lib/tftpboot/mboot.c32' }
- { src: '/usr/share/syslinux/memdisk', dest: '/var/lib/tftpboot/memdisk' }
- { src: '/usr/share/syslinux/menu.c32', dest: '/var/lib/tftpboot/menu.c32' }
- { src: '/usr/share/syslinux/pxelinux.0', dest: '/var/lib/tftpboot/pxelinux.0' }
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
- name: Copy files from syslinux for Ubuntu
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ lookup('env', 'USER') }}"
group: "{{ lookup('env', 'USER') }}"
mode: 0777
become: true
with_items:
- { src: '/usr/lib/syslinux/modules/bios/chain.c32', dest: '/tftpboot/chain.c32' }
- { src: '/usr/lib/syslinux/modules/bios/mboot.c32', dest: '/tftpboot/mboot.c32' }
- { src: '/usr/lib/syslinux/memdisk', dest: '/tftpboot/memdisk' }
- { src: '/usr/lib/syslinux/modules/bios/menu.c32', dest: '/tftpboot/menu.c32' }
- { src: '/usr/lib/PXELINUX/pxelinux.0', dest: '/tftpboot/pxelinux.0' }
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Install dnsmasq
package:
name: dnsmasq
become: true
- name: Comment/uncomment options in dnsmasq.conf
lineinfile:
path: /etc/dnsmasq.conf
backrefs: yes
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
become: true
with_items:
- { regexp: '#log-dhcp', line: 'log-dhcp' }
- { regexp: 'conf-dir=/etc/dnsmasq.d', line: '#conf-dir=/etc/dnsmasq.d' }
# This is just an example configuration. Modify to match your requirements.
- name: Add DHCP configuration to dnsmasq.conf
lineinfile:
path: /etc/dnsmasq.conf
line: "{{ item }}"
become: true
with_items:
- 'interface=eth2'
- 'dhcp-range=10.10.10.50,10.10.10.100,7d'
- 'dhcp-boot=pxelinux.0'
- 'enable-tftp'
- 'tftp-root=/var/lib/tftpboot'
- 'dhcp-userclass=set:ENH,iPXE'
- name: Systemctl commands for dnsmasq
systemd:
name: dnsmasq
daemon-reload: yes
state: started
enabled: yes
become: true