Skip to content

Commit faaa52a

Browse files
authored
Merge pull request #17 from CarlFK/http-config
Serve preseed and late_command over http
2 parents 2328e63 + dad9cb0 commit faaa52a

8 files changed

Lines changed: 146 additions & 37 deletions

File tree

roles/tftp-server/defaults/main.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
netboot_image: https://deb.debian.org/debian/dists/stretch/main/installer-amd64/current/images/netboot/netboot.tar.gz
3-
late_command_url: https://anonscm.debian.org/cgit/debconf-video/ansible.git/plain/setup_ansible.sh
43

54
time_zone: UTC
65
domain: video.debconf.org
@@ -12,3 +11,11 @@ apt_proxy: false
1211
user_name: videoteam
1312
# Defaults to not setting a password
1413
#user_password_crypted: changeme
14+
15+
# Git repos:
16+
playbook_repo: https://anonscm.debian.org/cgit/debconf-video/ansible.git
17+
playbook_branch: master
18+
19+
# To replace the stock inventory with your own, point at your own github repo
20+
#inventory_repo: https://gitlab.com/yourname/ansible-inventory
21+
#inventory_branch: master

roles/tftp-server/files/pxe

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server {
2+
listen 80 default_server;
3+
listen [::]:80 default_server;
4+
5+
root /srv/pxe;
6+
7+
server_name {{ inventory_hostname }}.{{ video.debconf.org }};
8+
9+
location / {
10+
fancyindex on;
11+
}
12+
13+
access_log /var/log/nginx/pxe-access.log;
14+
error_log /var/log/nginx/pxe-error.log;
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
- name: systemctl restart nginx
3+
command: systemctl restart nginx

roles/tftp-server/tasks/d-i.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
- name: download TFTP boot image
3+
get_url:
4+
url: "{{ netboot_image }}"
5+
dest: /srv/tftp/netboot.tar.gz
6+
7+
- name: extract TFTP boot image
8+
unarchive:
9+
src: /srv/tftp/netboot.tar.gz
10+
dest: /srv/tftp
11+
remote_src: true
12+
creates: /srv/tftp/pxelinux.0
13+
14+
- name: inject preseed into menu (find files)
15+
find:
16+
paths: /srv/tftp
17+
recurse: true
18+
patterns: txt.cfg
19+
register: menus
20+
21+
- name: inject preseed into menu (do injection)
22+
lineinfile:
23+
dest: "{{ item.path }}"
24+
regexp: (\s+append\s+.*\s+initrd=\S+)\s+(?!auto=true)(.*)
25+
backrefs: true
26+
line: \1 auto=true interface=auto url={{ inventory_hostname }} \2
27+
with_items: "{{ menus.files }}"
28+
29+
- name: create d-i directory
30+
file:
31+
path: /srv/pxe/d-i/{{ debian_version }}
32+
state: directory
33+
recurse: true
34+
35+
- name: write preseed.cfg
36+
template:
37+
src: preseed.cfg.j2
38+
dest: /srv/pxe/d-i/{{ debian_version }}/preseed.cfg
39+
40+
- name: generate late_command.sh
41+
template:
42+
src: late_command.sh.j2
43+
dest: /srv/pxe/d-i/late_command.sh

roles/tftp-server/tasks/main.yml

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
11
---
2-
- name: download TFTP boot image
3-
get_url:
4-
url: "{{ netboot_image }}"
5-
dest: /srv/tftp/netboot.tar.gz
6-
7-
- name: extract TFTP boot image
8-
unarchive:
9-
src: /srv/tftp/netboot.tar.gz
10-
dest: /srv/tftp
11-
remote_src: true
12-
creates: /srv/tftp/pxelinux.0
13-
14-
- name: write preseed.cfg
15-
template:
16-
src: preseed.cfg.j2
17-
dest: /srv/tftp/preseed.cfg
18-
19-
- name: inject preseed into menu (find files)
20-
find:
21-
paths: /srv/tftp
22-
recurse: true
23-
patterns: txt.cfg
24-
register: menus
25-
26-
- name: inject preseed into menu (do injection)
27-
lineinfile:
28-
dest: "{{ item.path }}"
29-
regexp: (\s+append\s+.*\s+initrd=\S+)\s+(?!auto=true)(.*)
30-
backrefs: true
31-
line: \1 auto=true interface=auto url=tftp://10.20.0.1/preseed.cfg \2
32-
with_items: "{{ menus.files }}"
2+
- include: webserver.yml
3+
- include: d-i.yml
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: install nginx
3+
apt:
4+
name: nginx-extras
5+
6+
- name: remove default nginx vhost
7+
file: /etc/nginx/sites-available/default
8+
state: absent
9+
notify: systemctl restart nginx
10+
11+
- name: place pxe nginx vhost
12+
copy:
13+
src: files/pxe
14+
dest: /etc/nginx/sites-available/pxe
15+
notify: systemctl restart nginx
16+
17+
- name: enable pxe nginx vhost
18+
file:
19+
state: link
20+
src: /etc/nginx/sites-available/pxe
21+
dest: /etc/nginx/sites-enabled/pxe
22+
notify: systemctl restart nginx
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
3+
set -eufx
4+
5+
# This script setups ansible and runs it
6+
# It should be ran at the end of the basic installation of a machine
7+
8+
apt install -y ansible git eatmydata
9+
10+
# We clone our ansible repository and copy the ansible config files
11+
12+
git clone {{ playbook_repo }} /root/playbook-repo
13+
(cd /root/playbook-repo; git checkout {{ playbook_branch }})
14+
INVENTORY=/root/playbook-repo/inventory/hosts
15+
PLAYBOOKS=/root/playbook-repo/site.yml
16+
17+
{% if inventory_repo is defined %}
18+
git clone {{ inventory_repo }} /root/inventory-repo
19+
(cd /root/inventory-repo; git checkout {{ inventory_branch }})
20+
INVENTORY=/root/inventory-repo/inventory/hosts
21+
if [ -e /root/inventory-repo/site.yml ]; then
22+
PLAYBOOKS="$PLAYBOOKS /root/inventory-repo/site.yml"
23+
fi
24+
{% endif %}
25+
26+
cat > /usr/local/sbin/ansible-up <<EOF
27+
#!/bin/sh
28+
29+
set -euf
30+
31+
cd /root/
32+
33+
(cd playbook-repo; git pull)
34+
{% if inventory_repo is defined %}
35+
(cd inventory-repo; git pull)
36+
{% endif %}
37+
38+
exec ansible-playbook \
39+
--inventory-file=$INVENTORY \
40+
--connection=local \
41+
--limit=\$(hostname) \
42+
$PLAYBOOKS \
43+
"\$@"
44+
EOF
45+
chmod +x /usr/local/sbin/ansible-up
46+
47+
eatmydata ansible-playbook \
48+
-vvvv \
49+
--inventory-file=$INVENTORY \
50+
--connection=local \
51+
--limit=$(hostname) \
52+
$PLAYBOOKS

roles/tftp-server/templates/preseed.cfg.j2

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,7 @@ d-i finish-install/reboot_in_progress note
438438
# still a usable /target directory. You can chroot to /target and use it
439439
# directly, or use the apt-install and in-target commands to easily install
440440
# packages and run commands in the target system.
441-
{% if late_command_url.startswith('tftp://') %}
442-
d-i preseed/late_command string in-target sh -c "curl -o penultimate_setup.sh '{{ late_command_url }}' && ANSIBLE_UNDER_DI=1 sh penultimate_setup.sh && rm penultimate_setup.sh"
443-
{% else %}
444-
d-i preseed/late_command string in-target sh -c "wget -O penultimate_setup.sh '{{ late_command_url }}' && ANSIBLE_UNDER_DI=1 sh penultimate_setup.sh && rm penultimate_setup.sh"
445-
{% endif %}
441+
d-i preseed/late_command string in-target sh -c "curl -o late_command.sh 'http://{{ inventory_hostname }}/d-i/late_command.sh' && ANSIBLE_UNDER_DI=1 sh late_command.sh && rm late_command.sh"
446442

447443
# don't ask for extra firmare
448444
d-i hw-detect/load_firmware boolean false

0 commit comments

Comments
 (0)