diff --git a/roles/dhcp-server/handlers/main.yml b/roles/dhcp-server/handlers/main.yml index 3815964..5ef2e33 100644 --- a/roles/dhcp-server/handlers/main.yml +++ b/roles/dhcp-server/handlers/main.yml @@ -1,6 +1,7 @@ --- - name: restart networking command: "/bin/systemctl restart networking.service" + ignore_errors: yes - name: restart dnsmasq command: "/bin/systemctl restart dnsmasq.service" diff --git a/roles/dhcp-server/tasks/main.yml b/roles/dhcp-server/tasks/main.yml index c0b7dc3..5fe3c04 100644 --- a/roles/dhcp-server/tasks/main.yml +++ b/roles/dhcp-server/tasks/main.yml @@ -17,6 +17,7 @@ dest: /etc/network/interfaces when: use_static_ip notify: restart networking + ignore_errors: yes - name: configure network interfaces (dhcp) template: @@ -24,6 +25,7 @@ dest: /etc/network/interfaces when: not use_static_ip notify: restart networking + ignore_errors: yes - name: ensure network-manager doesn't run its own dnsmasq lineinfile: diff --git a/roles/dhcp-server/templates/local.conf.j2 b/roles/dhcp-server/templates/local.conf.j2 index f18add6..5d7ac4b 100644 --- a/roles/dhcp-server/templates/local.conf.j2 +++ b/roles/dhcp-server/templates/local.conf.j2 @@ -8,3 +8,6 @@ dhcp-boot=pxelinux.0 dhcp-authoritative enable-tftp tftp-root=/srv/tftp +no-hosts +host-record={{ inventory_hostname }},{{ eth_local_ip_address }} +host-record={{ inventory_hostname }}.{{ domain }},{{ eth_local_ip_address }} diff --git a/roles/system-software/handlers/main.yml b/roles/system-software/handlers/main.yml index 0b80e1e..c5ae447 100644 --- a/roles/system-software/handlers/main.yml +++ b/roles/system-software/handlers/main.yml @@ -1,3 +1,4 @@ --- - name: restart systemd-journald command: systemctl restart systemd-journald + when: ansible_env.ANSIBLE_UNDER_DI is undefined diff --git a/roles/tftp-server/defaults/main.yml b/roles/tftp-server/defaults/main.yml index fcb9ae5..252f8a9 100644 --- a/roles/tftp-server/defaults/main.yml +++ b/roles/tftp-server/defaults/main.yml @@ -8,6 +8,8 @@ apt_proxy: false # Defaults to deb.debian.org | archive.ubuntu.com #mirror: deb.debian.org +web_root: /var/www/html + user_name: videoteam # Defaults to not setting a password #user_password_crypted: changeme @@ -19,3 +21,7 @@ playbook_branch: master # To replace the stock inventory with your own, point at your own github repo #inventory_repo: https://gitlab.com/yourname/ansible-inventory #inventory_branch: master + +# What Distro to install? +# Debian or Ubuntu +distro: Debian diff --git a/roles/tftp-server/files/late_command.sh b/roles/tftp-server/files/late_command.sh new file mode 100644 index 0000000..f934cee --- /dev/null +++ b/roles/tftp-server/files/late_command.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +set -eufx + +# This script setups ansible and runs it +# It should be ran at the end of the basic installation of a machine + +# apt install -y software-properties-common +# apt-add-repository --yes --update "deb http://ppa.launchpad.net/ansible/ansible/ubuntu xenial main" +# apt-add-repository --yes --update ppa:ansible/ansible + +apt install -y ansible git eatmydata + +# We clone our ansible repository and copy the ansible config files + +# git clone https://anonscm.debian.org/git/debconf-video/ansible.git /root/debconf-ansible +git clone https://github.com/CarlFK/video-stack-deploy.git /root/debconf-ansible +cd /root/debconf-ansible +git checkout pxe-toucheup +cd - + +git clone https://github.com/xfxf/av-foss-stack.git /root/lca2017-av + +ln -s /root/lca2017-av/inventory/ansible-up.sh /usr/local/sbin/ansible-up + +# not sure why sometimes this is only needed when I run from a prompt in the installer shell, +# but the istaller doesn't. or something. I'm not sure when it is needed. +mkdir /dev/shm +echo "none /dev/shm tmpfs rw,nosuid,nodev,noexec,noauto 0 0" >> /etc/fstab +mount /dev/shm + +# Aaaand we run ansible +eatmydata ansible-playbook \ + -vvvv \ + --connection=local \ + --limit=$(hostname) \ + --inventory-file=/root/lca2017-av/inventory/hosts \ + /root/debconf-ansible/site.yml diff --git a/roles/tftp-server/tasks/d-i.yml b/roles/tftp-server/tasks/d-i.yml index c63c189..eefc81f 100644 --- a/roles/tftp-server/tasks/d-i.yml +++ b/roles/tftp-server/tasks/d-i.yml @@ -21,21 +21,27 @@ - name: inject preseed into menu (do injection) lineinfile: dest: "{{ item.path }}" - regexp: (\s+append\s+.*\s+initrd=\S+)\s+(?!auto=true)(.*) + regexp: (\s+append vga=.*\s+initrd=\S+)\s+(?!auto=true)(.*) backrefs: true - line: \1 auto=true interface=auto url={{ inventory_hostname }} \2 + line: \1 auto=true interface=auto url={{ inventory_hostname }} DEBCONF_DEBUG=5 partman-auto/disk="/dev/sda" \2 with_items: "{{ menus.files }}" - name: create d-i directory file: - path: /srv/pxe/d-i/{{ debian_version }} + path: /srv/pxe/d-i/{{ item }} state: directory recurse: true + with_items: + - stretch + - xenial - name: write preseed.cfg template: src: preseed.cfg.j2 - dest: /srv/pxe/d-i/{{ debian_version }}/preseed.cfg + dest: /srv/pxe/d-i/{{ item }}/preseed.cfg + with_items: + - stretch + - xenial - name: generate late_command.sh template: diff --git a/roles/tftp-server/templates/preseed.cfg.j2 b/roles/tftp-server/templates/preseed.cfg.j2 index aa61da2..ca5a734 100644 --- a/roles/tftp-server/templates/preseed.cfg.j2 +++ b/roles/tftp-server/templates/preseed.cfg.j2 @@ -12,9 +12,9 @@ d-i debian-installer/locale string en_US #d-i localechooser/supported-locales multiselect en_US.UTF-8, nl_NL.UTF-8 # Keyboard selection. -{% if ansible_distribution == 'Debian' %} +{% if distro == 'Debian' %} d-i keyboard-configuration/xkb-keymap select us -{% elif ansible_distribution == 'Ubuntu' %} +{% elif distro == 'Ubuntu' %} d-i keyboard-configuration/layoutcode string us {% endif %} # d-i keyboard-configuration/toggle select No toggling @@ -102,10 +102,10 @@ d-i netcfg/wireless_wep string # If you select ftp, the mirror/country string does not need to be set. #d-i mirror/protocol string ftp d-i mirror/country string manual -{% if ansible_distribution == 'Debian' %} +{% if distro == 'Debian' %} d-i mirror/http/hostname string {{ mirror | default('deb.debian.org') }} d-i mirror/http/directory string /debian -{% elif ansible_distribution == 'Ubuntu' %} +{% elif distro == 'Ubuntu' %} d-i mirror/http/hostname string {{ mirror | default('archive.ubuntu.com') }} d-i mirror/http/directory string /ubuntu {% endif %} @@ -132,7 +132,7 @@ d-i passwd/username string {{ user_name }} {% if user_password_crypted is defined %} d-i passwd/user-password-crypted password {{ user_password_crypted }} {% endif %} -{% if ansible_distribution == 'Ubuntu' %} +{% if distro == 'Ubuntu' %} # Ubuntu offers encrypted home directories d-i user-setup/encrypt-home boolean false {% endif %} @@ -165,7 +165,7 @@ d-i clock-setup/ntp boolean true # name must be given in traditional, non-devfs format (so e.g. /dev/hda or # /dev/sda, and not e.g. /dev/discs/disc0/disc). # For example, to use the first SCSI/SATA hard disk: -d-i partman-auto/disk string /dev/sda +# d-i partman-auto/disk string /dev/sda # In addition, you'll need to specify the method to use. # The presently available methods are: # - regular: use the usual partition types for your architecture @@ -183,7 +183,7 @@ d-i partman-md/device_remove_md boolean true d-i partman-lvm/confirm boolean true d-i partman-lvm/confirm_nooverwrite boolean true -{% if ansible_distribution == 'Ubuntu' %} +{% if distro == 'Ubuntu' %} # Use all the space on LVM d-i partman-auto-lvm/guided_size string max {% endif %} @@ -239,7 +239,7 @@ d-i partman/confirm_nooverwrite boolean true # so this will only work if the disks are the same size. #d-i partman-auto/disk string /dev/sda /dev/sdb -# Next you need to specify the physical partitions that will be used. +# Next you need to specify the physical partitions that will be used. #d-i partman-auto/expert_recipe string \ # multiraid :: \ # 1000 5000 4000 raid \ @@ -309,10 +309,6 @@ d-i apt-setup/contrib boolean true #d-i apt-setup/services-select multiselect security, updates #d-i apt-setup/security_host string security.debian.org -{% if ansible_distribution == 'Ubuntu' %} -d-i pkgsel/update-policy string unattended-upgrades -{% endif %} - # Additional repositories, local[0-9] available #d-i apt-setup/local0/repository string \ # http://local.server/debian stable main @@ -335,11 +331,15 @@ d-i apt-setup/local0/key string file:///hd-media/ac583520.asc tasksel tasksel/first multiselect standard # Individual additional packages to install -d-i pkgsel/include string openssh-server curl +d-i pkgsel/include string openssh-server curl python python3 # grub-ipxe # Whether to upgrade packages after debootstrap. # Allowed values: none, safe-upgrade, full-upgrade #d-i pkgsel/upgrade select none +{% if distro == 'Ubuntu' %} +d-i pkgsel/update-policy string unattended-upgrades +{% endif %} + # Some versions of the installer can report back on what software you have # installed, and what software you use. The default is not to report back, # but sending reports helps the project determine what software is most @@ -365,9 +365,9 @@ d-i grub-installer/with_other_os boolean true # Due notably to potential USB sticks, the location of the MBR can not be # determined safely in general, so this needs to be specified: -d-i grub-installer/bootdev string /dev/sda +# d-i grub-installer/bootdev string /dev/sda # To install to the first device (assuming it is not a USB stick): -#d-i grub-installer/bootdev string default +d-i grub-installer/bootdev string default # Alternatively, if you want to install to a location other than the mbr, # uncomment and edit these lines: @@ -428,7 +428,8 @@ d-i finish-install/reboot_in_progress note # This first command is run as early as possible, just after # preseeding is read. -#d-i preseed/early_command string anna-install some-udeb +d-i preseed/early_command string cd /tmp && wget http://$url/ec/early_command.sh && chmod u+x early_command.sh && ./early_command.sh + # This command is run immediately before the partitioner starts. It may be # useful to apply dynamic partitioner preseeding that depends on the state # of the disks (which may not be visible when preseed/early_command runs). @@ -438,7 +439,7 @@ d-i finish-install/reboot_in_progress note # still a usable /target directory. You can chroot to /target and use it # directly, or use the apt-install and in-target commands to easily install # packages and run commands in the target system. -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" +d-i preseed/late_command string cd /target/tmp && wget http://$url/d-i/late_command.sh && chmod u+x late_command.sh && chroot /target unset http_proxy; ANSIBLE_UNDER_DI=1 /tmp/late_command.sh $(debconf-get mirror/suite) $(debconf-get passwd/username) # don't ask for extra firmare d-i hw-detect/load_firmware boolean false