From ff59effbb1216dba42386f4763c5488acfc1db0f Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Mon, 2 May 2022 22:03:37 -0500 Subject: [PATCH] Ubuntu 20.04 on QEmu working --- .gitignore | 4 + Vagrantfile | 43 ++++++++ ansible/playbook.yml | 24 +++++ ansible/roles/cleanup/tasks/CentOS.yml | 7 ++ ansible/roles/cleanup/tasks/CentOS_6.yml | 8 ++ ansible/roles/cleanup/tasks/CentOS_7.yml | 11 ++ ansible/roles/cleanup/tasks/Fedora.yml | 4 + ansible/roles/cleanup/tasks/Ubuntu.yml | 3 + ansible/roles/cleanup/tasks/main.yml | 8 ++ ansible/roles/epel/tasks/main.yml | 16 +++ ansible/roles/init/tasks/main.yml | 16 +++ ansible/roles/init/vars/CentOS_6.yml | 3 + ansible/roles/init/vars/Ubuntu.yml | 3 + ansible/roles/locale/tasks/main.yml | 9 ++ ansible/roles/vagrant/tasks/main.yml | 69 +++++++++++++ ansible/roles/vagrant/vars/Ubuntu.yml | 1 + ansible/roles/vagrant/vars/default.yml | 1 + ansible/roles/virtualbox/tasks/main.yml | 27 +++++ ansible/roles/virtualbox/vars/CentOS.yml | 8 ++ ansible/roles/virtualbox/vars/Fedora.yml | 7 ++ ansible/roles/virtualbox/vars/Ubuntu.yml | 5 + ansible/roles/vmware/tasks/has_package.yml | 5 + ansible/roles/vmware/tasks/legacy.yml | 45 ++++++++ ansible/roles/vmware/tasks/main.yml | 25 +++++ ansible/roles/vmware/vars/CentOS-6.yml | 6 ++ ansible/roles/vmware/vars/CentOS.yml | 2 + ansible/roles/vmware/vars/Debian-8.yml | 4 + ansible/roles/vmware/vars/Debian.yml | 2 + ansible/roles/vmware/vars/Fedora.yml | 2 + ansible/roles/vmware/vars/Ubuntu.yml | 2 + distros/ubuntu-20.04-x86_64.pkrvars.hcl | 13 +++ http/ubuntu/14.04/preseed.cfg | 1 + http/ubuntu/16.04/preseed.cfg | 3 + http/ubuntu/18.04/preseed.cfg | 19 ++++ http/ubuntu/20.04/meta-data | 0 http/ubuntu/20.04/user-data | 96 +++++++++++++++++ http/ubuntu/preseed.cfg | 60 +++++++++++ scripts/minimize.sh | 29 ++++++ sources/qemu.pkr.hcl | 113 +++++++++++++++++++++ test.sh | 10 ++ vagrant/ppc64le.rb | 13 +++ vagrant/silverblue.rb | 15 +++ vagrant/x86_64.rb | 15 +++ 43 files changed, 757 insertions(+) create mode 100644 .gitignore create mode 100644 Vagrantfile create mode 100644 ansible/playbook.yml create mode 100644 ansible/roles/cleanup/tasks/CentOS.yml create mode 100644 ansible/roles/cleanup/tasks/CentOS_6.yml create mode 100644 ansible/roles/cleanup/tasks/CentOS_7.yml create mode 100644 ansible/roles/cleanup/tasks/Fedora.yml create mode 100644 ansible/roles/cleanup/tasks/Ubuntu.yml create mode 100644 ansible/roles/cleanup/tasks/main.yml create mode 100644 ansible/roles/epel/tasks/main.yml create mode 100644 ansible/roles/init/tasks/main.yml create mode 100644 ansible/roles/init/vars/CentOS_6.yml create mode 100644 ansible/roles/init/vars/Ubuntu.yml create mode 100644 ansible/roles/locale/tasks/main.yml create mode 100644 ansible/roles/vagrant/tasks/main.yml create mode 100644 ansible/roles/vagrant/vars/Ubuntu.yml create mode 100644 ansible/roles/vagrant/vars/default.yml create mode 100644 ansible/roles/virtualbox/tasks/main.yml create mode 100644 ansible/roles/virtualbox/vars/CentOS.yml create mode 100644 ansible/roles/virtualbox/vars/Fedora.yml create mode 100644 ansible/roles/virtualbox/vars/Ubuntu.yml create mode 100644 ansible/roles/vmware/tasks/has_package.yml create mode 100644 ansible/roles/vmware/tasks/legacy.yml create mode 100644 ansible/roles/vmware/tasks/main.yml create mode 100644 ansible/roles/vmware/vars/CentOS-6.yml create mode 100644 ansible/roles/vmware/vars/CentOS.yml create mode 100644 ansible/roles/vmware/vars/Debian-8.yml create mode 100644 ansible/roles/vmware/vars/Debian.yml create mode 100644 ansible/roles/vmware/vars/Fedora.yml create mode 100644 ansible/roles/vmware/vars/Ubuntu.yml create mode 100644 distros/ubuntu-20.04-x86_64.pkrvars.hcl create mode 100644 http/ubuntu/14.04/preseed.cfg create mode 100644 http/ubuntu/16.04/preseed.cfg create mode 100644 http/ubuntu/18.04/preseed.cfg create mode 100644 http/ubuntu/20.04/meta-data create mode 100644 http/ubuntu/20.04/user-data create mode 100644 http/ubuntu/preseed.cfg create mode 100644 scripts/minimize.sh create mode 100644 sources/qemu.pkr.hcl create mode 100755 test.sh create mode 100644 vagrant/ppc64le.rb create mode 100644 vagrant/silverblue.rb create mode 100644 vagrant/x86_64.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39e4b7a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +output_* +*.box +*.iso +.vagrant diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..ff95b78 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,43 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + config.vm.box = "test" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + config.vm.synced_folder ".", "/vagrant", disabled: true + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Enable provisioning with a shell script. Additional provisioners such as + # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the + # documentation for more information about their specific syntax and use. + config.vm.provision "shell", inline: <<-SHELL + set -ex + ls -l / + SHELL +end diff --git a/ansible/playbook.yml b/ansible/playbook.yml new file mode 100644 index 0000000..43315af --- /dev/null +++ b/ansible/playbook.yml @@ -0,0 +1,24 @@ +- name: install guest additions + hosts: default + pre_tasks: + - name: update all the things + become: true + package: + name: "*" + state: latest + when: ansible_facts.pkg_mgr not in ['atomic_container'] + + - name: update atomic things + become: true + command: rpm-ostree upgrade + when: ansible_facts.pkg_mgr in ['atomic_container'] + roles: + - role: virtualbox + when: packer_builder_type == 'virtualbox-iso' + - role: vmware + when: packer_builder_type == 'vmware-iso' + - role: init + - role: epel + - role: locale + - role: vagrant + - role: cleanup diff --git a/ansible/roles/cleanup/tasks/CentOS.yml b/ansible/roles/cleanup/tasks/CentOS.yml new file mode 100644 index 0000000..5db6e35 --- /dev/null +++ b/ansible/roles/cleanup/tasks/CentOS.yml @@ -0,0 +1,7 @@ +- name: clean yum history + become: true + shell: |- + set -e + yum --enablerepo=epel clean all + yum history new + truncate -c -s 0 /var/log/yum.log diff --git a/ansible/roles/cleanup/tasks/CentOS_6.yml b/ansible/roles/cleanup/tasks/CentOS_6.yml new file mode 100644 index 0000000..1a1220f --- /dev/null +++ b/ansible/roles/cleanup/tasks/CentOS_6.yml @@ -0,0 +1,8 @@ +- name: remove unnecessesary packages + become: true + package: + name: + - perl + - gcc + - kernel-devel + state: absent diff --git a/ansible/roles/cleanup/tasks/CentOS_7.yml b/ansible/roles/cleanup/tasks/CentOS_7.yml new file mode 100644 index 0000000..b275005 --- /dev/null +++ b/ansible/roles/cleanup/tasks/CentOS_7.yml @@ -0,0 +1,11 @@ +- name: remove unnecessesary packages + become: true + package: + name: + - make + - perl + - gcc + - kernel-devel + - net-tools + - bzip2 + state: absent diff --git a/ansible/roles/cleanup/tasks/Fedora.yml b/ansible/roles/cleanup/tasks/Fedora.yml new file mode 100644 index 0000000..3936d83 --- /dev/null +++ b/ansible/roles/cleanup/tasks/Fedora.yml @@ -0,0 +1,4 @@ +- name: clean up Fedora + become: true + command: dnf clean all + when: ansible_facts.pkg_mgr not in ['atomic_container'] diff --git a/ansible/roles/cleanup/tasks/Ubuntu.yml b/ansible/roles/cleanup/tasks/Ubuntu.yml new file mode 100644 index 0000000..b351b48 --- /dev/null +++ b/ansible/roles/cleanup/tasks/Ubuntu.yml @@ -0,0 +1,3 @@ +- name: clean apt files + become: true + command: apt-get clean diff --git a/ansible/roles/cleanup/tasks/main.yml b/ansible/roles/cleanup/tasks/main.yml new file mode 100644 index 0000000..cf210d5 --- /dev/null +++ b/ansible/roles/cleanup/tasks/main.yml @@ -0,0 +1,8 @@ +- name: cleanup + include_tasks: "{{ distro }}" + loop: + - "{{ role_path }}/tasks/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_major_version'] }}.yml" + - "{{ role_path }}/tasks/{{ ansible_facts['distribution'] }}.yml" + when: distro is file + loop_control: + loop_var: distro diff --git a/ansible/roles/epel/tasks/main.yml b/ansible/roles/epel/tasks/main.yml new file mode 100644 index 0000000..3b29424 --- /dev/null +++ b/ansible/roles/epel/tasks/main.yml @@ -0,0 +1,16 @@ +- become: true + block: + - name: install epel-release + package: + name: epel-release + state: present + + - name: disable epel + ini_file: + path: /etc/yum.repos.d/epel.repo + section: epel + option: enabled + value: "0" + create: false + when: > + ansible_facts['distribution'] in ['CentOS', 'RHEL'] diff --git a/ansible/roles/init/tasks/main.yml b/ansible/roles/init/tasks/main.yml new file mode 100644 index 0000000..1da1292 --- /dev/null +++ b/ansible/roles/init/tasks/main.yml @@ -0,0 +1,16 @@ +- name: load version information + include_vars: "{{ item }}" + loop: + - "{{ role_path }}/vars/{{ ansible_facts['os_family'] }}.yml" + - "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}.yml" + - "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_major_version'] }}.yml" + - "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_version'] }}.yml" + when: item is file + +- name: modify init file + become: true + replace: + path: "{{ init_file }}" + replace: "{{ init_replace }}" + regexp: "{{ init_regexp }}" + when: init_file is defined diff --git a/ansible/roles/init/vars/CentOS_6.yml b/ansible/roles/init/vars/CentOS_6.yml new file mode 100644 index 0000000..493e5d7 --- /dev/null +++ b/ansible/roles/init/vars/CentOS_6.yml @@ -0,0 +1,3 @@ +init_file: /etc/sysconfig/init +init_regexp: "^ACTIVE_CONSOLES=.*$" +init_replace: ACTIVE_CONSOLES=/dev/tty1 diff --git a/ansible/roles/init/vars/Ubuntu.yml b/ansible/roles/init/vars/Ubuntu.yml new file mode 100644 index 0000000..be39d0f --- /dev/null +++ b/ansible/roles/init/vars/Ubuntu.yml @@ -0,0 +1,3 @@ +init_file: /etc/default/console-setup +init_regexp: '^(ACTIVE_CONSOLES="/dev/tty).*' +init_replace: \g<1>1 diff --git a/ansible/roles/locale/tasks/main.yml b/ansible/roles/locale/tasks/main.yml new file mode 100644 index 0000000..c3dc5a3 --- /dev/null +++ b/ansible/roles/locale/tasks/main.yml @@ -0,0 +1,9 @@ +- name: update locale info + become: true + shell: | + set -e + localedef --list-archive | grep -a -v en_US.utf8 | xargs sudo localedef --delete-from-archive + cp /usr/lib/locale/locale-archive{,.tmpl} + build-locale-archive + when: > + ansible_facts['distribution'] in ['CentOS'] diff --git a/ansible/roles/vagrant/tasks/main.yml b/ansible/roles/vagrant/tasks/main.yml new file mode 100644 index 0000000..5d17617 --- /dev/null +++ b/ansible/roles/vagrant/tasks/main.yml @@ -0,0 +1,69 @@ +- name: load vars, if needed + include_vars: "{{ item }}" + loop: + - "{{ role_path }}/vars/default.yml" + - "{{ role_path }}/vars/{{ ansible_facts.distribution }}.yml" + - "{{ role_path }}/vars/{{ ansible_facts.distribution }}_{{ ansible_facts.distribution_major_version }}.yml" + when: item is file + +- name: remove cloud-init + become: true + package: + name: cloud-init + state: absent + when: ansible_facts.pkg_mgr not in ['atomic_container'] + +- name: get build time + become: true + copy: + content: "{{ ansible_facts.date_time.date }}" + dest: /etc/vagrant_box_build_time + owner: root + group: root + mode: 0644 + +- name: create .ssh directory + file: + path: "{{ ansible_user_dir }}/.ssh" + state: directory + mode: "0700" + +- name: fetch authorized_keys + get_url: + mode: "0600" + dest: "{{ ansible_user_dir }}/.ssh/authorized_keys" + url: https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub + +- block: + - name: configure sshd + lineinfile: + line: UseDNS no + path: /etc/ssh/sshd_config + + - name: check for the sshd_config.d directory + stat: + path: /etc/ssh/sshd_config.d + register: _vagrant_sshd_config_d + + - name: be sure that sshd is configured properly to accept the pubkey + copy: + content: PubkeyAcceptedKeyTypes +ssh-rsa + mode: "0600" + owner: root + group: root + dest: /etc/ssh/sshd_config.d/00-vagrant_accept_pubkey.conf + when: _vagrant_sshd_config_d.stat.exists + + - name: enable sshd + service: + name: "{{ vagrant_ssh_service_name }}" + state: started + enabled: true + # Fedora 31 has a bug in systemd with kernel >= 5.8 that makes us + # unable to determine state of the service. However, if we were able + # to connect to it to run this Ansible, then we clearly are up + # and running and we can safely ignore this error + ignore_errors: >- + {{ ansible_facts.distribution == 'Fedora' and + ansible_facts.distribution_major_version == '31' }} + become: true diff --git a/ansible/roles/vagrant/vars/Ubuntu.yml b/ansible/roles/vagrant/vars/Ubuntu.yml new file mode 100644 index 0000000..6b4aaa1 --- /dev/null +++ b/ansible/roles/vagrant/vars/Ubuntu.yml @@ -0,0 +1 @@ +vagrant_ssh_service_name: ssh diff --git a/ansible/roles/vagrant/vars/default.yml b/ansible/roles/vagrant/vars/default.yml new file mode 100644 index 0000000..93b0cd5 --- /dev/null +++ b/ansible/roles/vagrant/vars/default.yml @@ -0,0 +1 @@ +vagrant_ssh_service_name: sshd diff --git a/ansible/roles/virtualbox/tasks/main.yml b/ansible/roles/virtualbox/tasks/main.yml new file mode 100644 index 0000000..3e130a3 --- /dev/null +++ b/ansible/roles/virtualbox/tasks/main.yml @@ -0,0 +1,27 @@ +- name: install build deps for virtualbox addons + become: true + package: + name: "{{ virtualbox_packages }}" + state: present + +- name: start services + become: true + service: + name: "{{ item }}" + state: started + enabled: true + loop: "{{ virtualbox_services }}" + +- name: mount iso file + become: true + command: "{{ item }}" + changed_when: false + loop: + - mount -o loop,ro {{ ansible_user_dir }}/VBoxGuestAdditions.iso /mnt + - /mnt/VBoxLinuxAdditions.run + - umount /mnt + +- name: remove iso + file: + name: "{{ ansible_user_dir }}/VBoxGuestAdditions.iso" + state: absent diff --git a/ansible/roles/virtualbox/vars/CentOS.yml b/ansible/roles/virtualbox/vars/CentOS.yml new file mode 100644 index 0000000..a65ba56 --- /dev/null +++ b/ansible/roles/virtualbox/vars/CentOS.yml @@ -0,0 +1,8 @@ +virtualbox_packages: + - bzip2 + - dkms + - kernel-devel + - make + - perl +virtualbox_services: + - dkms diff --git a/ansible/roles/virtualbox/vars/Fedora.yml b/ansible/roles/virtualbox/vars/Fedora.yml new file mode 100644 index 0000000..6ace794 --- /dev/null +++ b/ansible/roles/virtualbox/vars/Fedora.yml @@ -0,0 +1,7 @@ +virtualbox_packages: + - bzip2 + - dkms + - kernel-devel + - make +virtualbox_services: + - dkms diff --git a/ansible/roles/virtualbox/vars/Ubuntu.yml b/ansible/roles/virtualbox/vars/Ubuntu.yml new file mode 100644 index 0000000..eb6f954 --- /dev/null +++ b/ansible/roles/virtualbox/vars/Ubuntu.yml @@ -0,0 +1,5 @@ +virtualbox_packages: + - dkms + - make +virtualbox_services: + - dkms diff --git a/ansible/roles/vmware/tasks/has_package.yml b/ansible/roles/vmware/tasks/has_package.yml new file mode 100644 index 0000000..4990d29 --- /dev/null +++ b/ansible/roles/vmware/tasks/has_package.yml @@ -0,0 +1,5 @@ +- name: create hgfs dir + become: true + file: + state: directory + path: /mnt/hgfs diff --git a/ansible/roles/vmware/tasks/legacy.yml b/ansible/roles/vmware/tasks/legacy.yml new file mode 100644 index 0000000..35357fd --- /dev/null +++ b/ansible/roles/vmware/tasks/legacy.yml @@ -0,0 +1,45 @@ +- name: create mount point + become: true + file: + path: /mnt/vmware + state: directory + +- name: mount iso file + become: true + command: mount -o loop,ro {{ ansible_user_dir }}/linux.iso /mnt/vmware + +- name: create tmp dir + file: + path: /tmp/vmware + state: directory + +- name: untar tools + command: | + set -ex + tar zxf /mnt/vmware/VMWareTools-*.tar.gz -C /tmp/vmware + sudo /tmp/vmware/vmware-tools-distrib/vmware-install.pl --default --force-install + rm -r /tmp/vmware + sudo umount /mnt/vmware + changed_when: false + +- name: remove files + become: true + file: + path: "{{ item }}" + state: absent + loop: + - /mnt/vmware + - "{{ ansible_user_dir }}/linux.iso" + +- name: add content to /etc/vmware-tools/locations + blockinfile: + block: | + remove_answer ENABLE_VGAUTH + answer ENABLE_VGAUTH no + remove_answer ENABLE_VMBLOCK + answer ENABLE_VMBLOCK no + +- name: finish up installs + become: true + command: /usr/bin/vmware-config-tools.pl --default --skip-stop-abort + changed_when: false diff --git a/ansible/roles/vmware/tasks/main.yml b/ansible/roles/vmware/tasks/main.yml new file mode 100644 index 0000000..2bc0fa8 --- /dev/null +++ b/ansible/roles/vmware/tasks/main.yml @@ -0,0 +1,25 @@ +- name: read variables + include_vars: "{{ item }}" + loop: + - "{{ role_path }}/vars/{{ ansible_facts.distribution }}.yml" + - "{{ role_path }}/vars/{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml" + when: item is file + +- name: install vmware related packages + become: true + package: + name: "{{ vmware_packages }}" + state: present + +- name: modern systems + import_tasks: has_package.yml + when: >- + ansible_distribution_name == 'fedora' or + (ansible_distribution_name == 'debian' and + ansible_distribution_major_version > '8') + +- name: legacy builds + import_tasks: legacy.yml + when: >- + (ansible_distribution_name == 'debian' and + ansible_distribution_major_version <= '8') diff --git a/ansible/roles/vmware/vars/CentOS-6.yml b/ansible/roles/vmware/vars/CentOS-6.yml new file mode 100644 index 0000000..60814d9 --- /dev/null +++ b/ansible/roles/vmware/vars/CentOS-6.yml @@ -0,0 +1,6 @@ +vmware_packages: + - perl + - net-tools + - make + - gcc + - kernel-devel diff --git a/ansible/roles/vmware/vars/CentOS.yml b/ansible/roles/vmware/vars/CentOS.yml new file mode 100644 index 0000000..2dbdb60 --- /dev/null +++ b/ansible/roles/vmware/vars/CentOS.yml @@ -0,0 +1,2 @@ +vmware_packages: + - open-vm-tools diff --git a/ansible/roles/vmware/vars/Debian-8.yml b/ansible/roles/vmware/vars/Debian-8.yml new file mode 100644 index 0000000..c5ba0a0 --- /dev/null +++ b/ansible/roles/vmware/vars/Debian-8.yml @@ -0,0 +1,4 @@ +vmware_packages: + - perl + - make + - linux-headers-{{ ansible_architecture }} diff --git a/ansible/roles/vmware/vars/Debian.yml b/ansible/roles/vmware/vars/Debian.yml new file mode 100644 index 0000000..2dbdb60 --- /dev/null +++ b/ansible/roles/vmware/vars/Debian.yml @@ -0,0 +1,2 @@ +vmware_packages: + - open-vm-tools diff --git a/ansible/roles/vmware/vars/Fedora.yml b/ansible/roles/vmware/vars/Fedora.yml new file mode 100644 index 0000000..2dbdb60 --- /dev/null +++ b/ansible/roles/vmware/vars/Fedora.yml @@ -0,0 +1,2 @@ +vmware_packages: + - open-vm-tools diff --git a/ansible/roles/vmware/vars/Ubuntu.yml b/ansible/roles/vmware/vars/Ubuntu.yml new file mode 100644 index 0000000..2dbdb60 --- /dev/null +++ b/ansible/roles/vmware/vars/Ubuntu.yml @@ -0,0 +1,2 @@ +vmware_packages: + - open-vm-tools diff --git a/distros/ubuntu-20.04-x86_64.pkrvars.hcl b/distros/ubuntu-20.04-x86_64.pkrvars.hcl new file mode 100644 index 0000000..925e3ae --- /dev/null +++ b/distros/ubuntu-20.04-x86_64.pkrvars.hcl @@ -0,0 +1,13 @@ +distro = "ubuntu" +arch = "x86_64" +version = "20.04" +iso = { + url = "https://releases.ubuntu.com/20.04/ubuntu-20.04.4-live-server-amd64.iso" + checksum = "28ccdb56450e643bad03bb7bcf7507ce3d8d90e8bf09e38f6bd9ac298a98eaad" +} +boot_wait = "3s" +boot_command = [ + "", + "autoinstall ds=nocloud-net;s=http://{{.HTTPIP}}:{{.HTTPPort}}/ubuntu/20.04/" +] +ssh_handshake_attempts = 1000 diff --git a/http/ubuntu/14.04/preseed.cfg b/http/ubuntu/14.04/preseed.cfg new file mode 100644 index 0000000..4f018f2 --- /dev/null +++ b/http/ubuntu/14.04/preseed.cfg @@ -0,0 +1 @@ +d-i preseed/include string ../preseed.cfg diff --git a/http/ubuntu/16.04/preseed.cfg b/http/ubuntu/16.04/preseed.cfg new file mode 100644 index 0000000..3750484 --- /dev/null +++ b/http/ubuntu/16.04/preseed.cfg @@ -0,0 +1,3 @@ +d-i preseed/include string ../preseed.cfg + +d-i debian-installer/add-kernel-opts string net.ifnames=0 biosdevname=0 diff --git a/http/ubuntu/18.04/preseed.cfg b/http/ubuntu/18.04/preseed.cfg new file mode 100644 index 0000000..a2dda07 --- /dev/null +++ b/http/ubuntu/18.04/preseed.cfg @@ -0,0 +1,19 @@ +d-i preseed/include string /preseed/ubuntu-server-minimalvm.seed +d-i preseed/include string ../preseed.cfg + +d-i debian-installer/locale string en_US.UTF-8 +d-i debian-installer/language string en +d-i debian-installer/country string US + +d-i console-setup/ask_detect boolean false + +d-i keyboard-configuration/model select USA +d-i keyboard-configuration/layout select USA +d-i keyboard-configuration/variant select USA + +d-i grub-installer/bootdev string /dev/vda + +d-i netcfg/choose_interface select auto + +d-i mirror/http/mirror select us.archive.ubuntu.com +d-i mirror/http/proxy string diff --git a/http/ubuntu/20.04/meta-data b/http/ubuntu/20.04/meta-data new file mode 100644 index 0000000..e69de29 diff --git a/http/ubuntu/20.04/user-data b/http/ubuntu/20.04/user-data new file mode 100644 index 0000000..4dd6d9c --- /dev/null +++ b/http/ubuntu/20.04/user-data @@ -0,0 +1,96 @@ +#cloud-config +# vim: set ft=yaml: +autoinstall: + version: 1 + network: # Should disable networking, workaround for unattended-updates failing in install + version: 2 + refresh-installer: + update: yes + keyboard: + layout: us + storage: + config: + - id: drive + type: disk + ptable: gpt + name: hard-drive + preserve: false + grub_device: true + wipe: superblock + - id: bios-grub + type: partition + device: drive + size: 1M + flag: bios_grub + - id: boot-partition + type: partition + device: drive + size: 200M + name: boot + - id: swap-partition + type: partition + device: drive + size: 10% + name: swap + flag: swap + - id: root-partition + type: partition + device: drive + name: root + size: -1 + - id: boot-format + type: format + fstype: ext4 + volume: boot-partition + label: boot + preserve: false + - id: swap-format + type: format + fstype: swap + volume: swap-partition + label: swap + preserve: false + - id: root-format + type: format + fstype: ext4 + volume: root-partition + label: root + preserve: false + - type: mount + id: root-mount + device: root-format + path: / + - type: mount + id: boot-mount + device: boot-format + path: /boot + - type: mount + id: swap-mount + device: swap-format + path: none + identity: + hostname: vagrant + username: vagrant + password: $6$rounds=4096$mJTRlY/vwPMquLe0$s4Ld3ZnvF.pM86xzbAgQD7Xpi/NMVgyQNb5CEfabFgL6nLRsP56WtwA.o.Jg/xC6HaJmM2p5fCGIo37jmKVRI0 + ssh: + install-server: yes + authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key + allow-pw: yes + user-data: + disable_root: false + late-commands: + - echo 'Defaults:vagrant !requiretty' > /target/etc/sudoers.d/vagrant + - echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >> /target/etc/sudoers.d/vagrant + - chmod 440 /target/etc/sudoers.d/vagrant + # Restore network after bypassing unattended updates + - "echo -n 'network:\n version: 2\n ethernets:\n eth0:\n dhcp4: true\n dhcp-identifier: mac' > /target/etc/netplan/00-installer-config.yaml" + - netplan apply + - sed -i -E -e 's/GRUB_CMDLINE_LINUX="(.*)"/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevnames=0\1"/' /target/etc/default/grub + - mount -o bind /dev /target/dev + - mount -o bind /sys /target/sys + - mount -o bind /proc /target/proc + - chroot /target /usr/sbin/update-grub + packages: + - curl + - sudo diff --git a/http/ubuntu/preseed.cfg b/http/ubuntu/preseed.cfg new file mode 100644 index 0000000..e7945b7 --- /dev/null +++ b/http/ubuntu/preseed.cfg @@ -0,0 +1,60 @@ +d-i debian-installer/locale string en_US +d-i time/zone string UTC + +d-i keyboard-configuration/xkb-keymap select us + +d-i clock-setup/utc boolean true +d-i clock-setup/utc-auto boolean true + +d-i debian-installer/missing-provide select ${DEFAULT} + +d-i partman-auto/method string regular +d-i partman-auto/expert_recipe string \ + scheme :: \ + 200 0 200 ext4 \ + $primary{ } \ + $bootable{ } \ + method{ format } \ + format{ } \ + use_filesystem{ } \ + filesystem{ ext4 } \ + mountpoint{ /boot } . \ + 200% 0 200% linux-swap \ + $primary{ } \ + method{ swap } \ + format{ } . \ + 1 0 -1 ext4 \ + $primary{ } \ + method{ format } \ + format{ } \ + use_filesystem{ } \ + filesystem{ ext4 } \ + mountpoint{ / } . +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true + +d-i base-installer/excludes string laptop-detect + +d-i passwd/root-password-again password vagrant +d-i passwd/root-password password vagrant +d-i passwd/user-fullname string vagrant +d-i passwd/username string vagrant +d-i passwd/user-password password vagrant +d-i passwd/user-password-again password vagrant +d-i user-setup/allow-password-weak boolean true + +d-i pkgsel/include string curl openssh-server sudo +d-i pkgsel/language-packs multiselect +d-i pkgsel/upgrade select full-upgrade +d-i pkgsel/update-policy select none +tasksel tasksel/first multiselect ubuntu-server + +d-i finish-install/reboot_in_progress note + +d-i preseed/late_command string \ + echo 'Defaults:vagrant !requiretty' > /target/etc/sudoers.d/vagrant; \ + echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /target/etc/sudoers.d/vagrant; \ + chmod 440 /target/etc/sudoers.d/vagrant; \ + in-target update-initramfs -u diff --git a/scripts/minimize.sh b/scripts/minimize.sh new file mode 100644 index 0000000..f07bba9 --- /dev/null +++ b/scripts/minimize.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -e +set -x + +rm -rf /home/vagrant/.ansible +sudo rm -rf /root/.ansible + +#if [[ "${PACKER_BUILD_NAME}" != *"silverblue"* ]]; then + sudo dd if=/dev/zero of=/var/EMPTY bs=1M || : + sync + sudo rm /var/EMPTY + sync +#fi + +# In CentOS 7, blkid returns duplicate devices +swap_device_uuid=`sudo /sbin/blkid -t TYPE=swap -o value -s UUID | uniq` +swap_device_label=`sudo /sbin/blkid -t TYPE=swap -o value -s LABEL | uniq` +if [ -n "$swap_device_uuid" ]; then + swap_device=`readlink -f /dev/disk/by-uuid/"$swap_device_uuid"` +elif [ -n "$swap_device_label" ]; then + swap_device=`readlink -f /dev/disk/by-label/"$swap_device_label"` +fi + +if [ ! -z "${swap_device}" -a -e "${swap_device}" ]; then + sudo /sbin/swapoff "$swap_device" + sudo dd if=/dev/zero of="$swap_device" bs=1M || : + sudo /sbin/mkswap ${swap_device_label:+-L "$swap_device_label"} ${swap_device_uuid:+-U "$swap_device_uuid"} "$swap_device" +fi diff --git a/sources/qemu.pkr.hcl b/sources/qemu.pkr.hcl new file mode 100644 index 0000000..e03c827 --- /dev/null +++ b/sources/qemu.pkr.hcl @@ -0,0 +1,113 @@ +variable "iso" { + type = map(string) + description = "A map containing the URL and checksum for the ISO file" +} + +variable "distro" { + type = string + default = "unknown" +} + +variable "arch" { + type = string + default = "x86_64" +} + +variable "version" { + type = string + description = "The distro version being specified" +} + +variable "boot_wait" { + type = string + default = "20s" + description = "Length of time to wait before entering boot commands" +} + +variable "ssh" { + type = map(string) + default = { + username = "vagrant" + password = "vagrant" + } +} + +variable "boot_command" { + type = list(string) + default = [] +} + +variable "ssh_handshake_attempts" { + type = number + default = 100 +} + +variable "shutdown_command" { + type = string + default = "sudo systemctl poweroff" +} + +variable "disk_size" { + type = string + default = "20G" +} + +variable "headless" { + type = bool + default = true +} + +locals { + name = "${var.distro}-${var.version}-${var.arch}" +} + +source "qemu" "x86_64" { + iso_url = var.iso.url + iso_checksum = var.iso.checksum + output_directory = "output_${local.name}" + vm_name = "packer-${local.name}" + disk_size = var.disk_size + boot_wait = var.boot_wait + ssh_timeout = "358m" + ssh_username = var.ssh.username + ssh_password = var.ssh.password + headless = var.headless + boot_command = var.boot_command + http_directory = "http" + ssh_handshake_attempts = var.ssh_handshake_attempts + accelerator = "kvm" + cpus = 2 + memory = 2048 + qemuargs = [["-serial", "stdio"]] + shutdown_command = var.shutdown_command +} + +build { + sources = ["source.qemu.x86_64"] + + provisioner "ansible" { + playbook_file = "ansible/playbook.yml" + } + + provisioner "shell" { + scripts = [ + "scripts/minimize.sh" + ] + } + + post-processors { + post-processor "vagrant" { + keep_input_artifact = true + compression_level = 9 + output = "${local.name}.box" + vagrantfile_template = "vagrant/${var.arch}.rb" + } + + post-processor "vagrant-cloud" { + name = "upload" + box_tag = "greg-hellings/${local.name}" + version = "{{isotime \"2006010203\"}}" + version_description = templatefile("../README.box.md") + } + } +} diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..976c4b7 --- /dev/null +++ b/test.sh @@ -0,0 +1,10 @@ +#!env bash + +set -exo pipefail + +build="${1}" + +#packer build -var-file distros/${build}.pkrvars.hcl -except=upload sources/qemu.pkr.hcl +vagrant box add -f --name test ${build}.box +vagrant up +vagrant ssh -c "ls -la ~/" diff --git a/vagrant/ppc64le.rb b/vagrant/ppc64le.rb new file mode 100644 index 0000000..c927ea3 --- /dev/null +++ b/vagrant/ppc64le.rb @@ -0,0 +1,13 @@ +Vagrant.configure('2') do |config| + config.vm.provider :libvirt do |v, override| + override.vm.synced_folder '', '/vagrant', disabled: true + v.driver = 'qemu' + v.machine_arch = 'ppc64' + v.machine_type = 'pseries' + v.cpu_mode = 'custom' + v.cpu_model = 'POWER8' + v.video_type = 'vga' + #v.qemuargs :value => '-nodefaults' + #v.qemuargs :value => '-nographic' + end +end diff --git a/vagrant/silverblue.rb b/vagrant/silverblue.rb new file mode 100644 index 0000000..2da51b8 --- /dev/null +++ b/vagrant/silverblue.rb @@ -0,0 +1,15 @@ +Vagrant.configure('2') do |c| + c.vm.synced_folder ".", "/home/vagrant/vagrant", type: "rsync" + # Set some basic overrides + c.vm.provider :libvirt do |v, override| + v.driver = 'kvm' + v.connect_via_ssh = false + v.username = 'root' + end + c.vm.provider :virtualbox do |v| + v.gui = false + end + c.vm.provider :vmware_fusion do |v| + v.gui = false + end +end diff --git a/vagrant/x86_64.rb b/vagrant/x86_64.rb new file mode 100644 index 0000000..d215f5a --- /dev/null +++ b/vagrant/x86_64.rb @@ -0,0 +1,15 @@ +Vagrant.configure('2') do |c| + c.vm.synced_folder ".", "/vagrant", type: "rsync" + # Set some basic overrides + c.vm.provider :libvirt do |v, override| + v.driver = 'kvm' + v.connect_via_ssh = false + v.username = 'root' + end + c.vm.provider :virtualbox do |v| + v.gui = false + end + c.vm.provider :vmware_fusion do |v| + v.gui = false + end +end