diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 73e7cf4..dfa86eb 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -1,46 +1,13 @@ - name: install guest additions hosts: default + vars: + ansible_remote_tmp: /tmp pre_tasks: - name: Pause for a moment in case we need cloud-init to finish ansible.builtin.pause: seconds: 20 - - - name: Update all the things - become: true - ansible.builtin.package: # noqa package-latest - name: "*" - state: latest - update_cache: true - when: ansible_facts.pkg_mgr not in ['atomic_container'] - register: _update_all - retries: 3 - until: _update_all is success - - - name: Update atomic things - become: true - ansible.builtin.command: rpm-ostree upgrade - when: ansible_facts.pkg_mgr in ['atomic_container'] - changed_when: false - register: _update_atomic - retries: 3 - until: _update_atomic is success - - - name: Reboot, but don't care if it doesn't - block: - - name: Restart the machine - become: true - ansible.builtin.reboot: - when: (_update_atomic is changed) or (_update_all is changed) - failed_when: false # This module is buggy and can't always understand a reboot - - - name: Wait for reboot to finish - ansible.builtin.wait_for_connection: - delay: 15 - rescue: - - name: Reboot failed? lol - ansible.builtin.debug: - msg: Reboot failed. lol. roles: + - role: latest - role: devroles.system.epel - role: virtualbox when: packer_builder_type == 'virtualbox-iso' diff --git a/ansible/roles/latest/tasks/Archlinux.yml b/ansible/roles/latest/tasks/Archlinux.yml new file mode 100644 index 0000000..ebb5ba1 --- /dev/null +++ b/ansible/roles/latest/tasks/Archlinux.yml @@ -0,0 +1,6 @@ +- name: Update on Arch + become: true + community.general.pacman: + upgrade: true + update_cache: true + state: latest diff --git a/ansible/roles/latest/tasks/Silverblue.yml b/ansible/roles/latest/tasks/Silverblue.yml new file mode 100644 index 0000000..ac308a7 --- /dev/null +++ b/ansible/roles/latest/tasks/Silverblue.yml @@ -0,0 +1,7 @@ +- name: Update atomic things + become: true + ansible.builtin.command: rpm-ostree upgrade + changed_when: false + register: _update_atomic + retries: 3 + until: _update_atomic is success diff --git a/ansible/roles/latest/tasks/default.yml b/ansible/roles/latest/tasks/default.yml new file mode 100644 index 0000000..8c12dc0 --- /dev/null +++ b/ansible/roles/latest/tasks/default.yml @@ -0,0 +1,9 @@ +- name: Update all the things + become: true + ansible.builtin.package: # noqa package-latest + name: "*" + state: latest + update_cache: true + register: _update_all + retries: 3 + until: _update_all is success diff --git a/ansible/roles/latest/tasks/main.yml b/ansible/roles/latest/tasks/main.yml new file mode 100644 index 0000000..a671215 --- /dev/null +++ b/ansible/roles/latest/tasks/main.yml @@ -0,0 +1,25 @@ +- name: Load update sciprt for proper distro + ansible.builtin.include_tasks: + file: "{{ item }}" + with_first_found: + - files: + - "{{ role_path }}/tasks/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_version'] }}.yml" + - "{{ role_path }}/tasks/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_major_version'] }}.yml" + - "{{ role_path }}/tasks/{{ ansible_facts['distribution'] }}.yml" + - "{{ role_path }}/tasks/{{ ansible_facts['os_family'] }}.yml" + - "{{ role_path }}/tasks/default.yml" + +- name: Reboot, but don't care if it doesn't + block: + - name: Restart the machine + become: true + ansible.builtin.reboot: + failed_when: false # This module is buggy and can't always understand a reboot + + - name: Wait for reboot to finish + ansible.builtin.wait_for_connection: + delay: 15 + rescue: + - name: Reboot failed? lol + ansible.builtin.debug: + msg: Reboot failed. lol. diff --git a/ansible/roles/virtualbox/tasks/main.yml b/ansible/roles/virtualbox/tasks/main.yml index 83b78ca..5fd8be5 100644 --- a/ansible/roles/virtualbox/tasks/main.yml +++ b/ansible/roles/virtualbox/tasks/main.yml @@ -54,6 +54,7 @@ ansible.builtin.package: name: "{{ virtualbox_remove_packages | default([]) }}" state: absent + when: virtualbox_remove_packages - name: Remove file ansible.builtin.file: diff --git a/ansible/roles/virtualbox/vars/Archlinux.yml b/ansible/roles/virtualbox/vars/Archlinux.yml new file mode 100644 index 0000000..90c3619 --- /dev/null +++ b/ansible/roles/virtualbox/vars/Archlinux.yml @@ -0,0 +1,6 @@ +virtualbox_packages: + - virtualbox-guest-utils-nox +virtualbox_services: + - vboxservice +virtualbox_from_iso: false +virtualbox_remove_packages: [] diff --git a/distros/arch/2023.08.01/http/in-chroot.sh b/distros/arch/2023.08.01/http/in-chroot.sh new file mode 100644 index 0000000..3b97759 --- /dev/null +++ b/distros/arch/2023.08.01/http/in-chroot.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -ex + +disk="${1}" + +# Set locale info to reasonable defaults +ln -sf /usr/share/zoneinfo/UTC /etc/localtime +sed -i -E -e 's/#(en_US.UTF-8 UTF-8)/\1/' /etc/locale.gen +locale-gen +echo "LANG=en_US.UTF-8" > /etc/locale.conf +echo "KEYMAP=en" > /etc/vconsole.conf + +echo "vagrant" > /etc/hostname + +# Configure systems +echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/vagrant-nopasswd +echo 'Defaults !requiretty' >> /etc/sudoers +sed -i 's/.*UseDNS.*/UseDNS no/' /etc/ssh/sshd_config +cat > /etc/ssh/sshd_config.d/10-vagrant-insecure-rsa-key.conf < ~vagrant/.ssh/authorized_keys << EOKEYS +ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key +EOKEYS +chmod 600 ~vagrant/.ssh/authorized_keys +chown -R vagrant:vagrant ~vagrant/ diff --git a/distros/arch/2023.08.01/http/install.sh b/distros/arch/2023.08.01/http/install.sh new file mode 100644 index 0000000..ac471a2 --- /dev/null +++ b/distros/arch/2023.08.01/http/install.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +#vim: set ft=bash: +set -ex + +port="${1}" # HTTP port that packer is running on + +loadkeys en # Probably not necessary in a script, but here we are + +if [ -e /dev/vda ]; then + disk="/dev/vda" +elif [ -e /dev/sda ]; then + disk="/dev/sda" +else + exit 1 # Need to teach the script which device to use in this case +fi + +# The sed bit is just to strip out the extra fluff, like comments +sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk ${disk} + o # create new GPT partition table + n # new + p # primary partition + 1 # part number + # default start + # default to full disk + p # print, for debugging + r # return to normal mode + w # write the partition table and exit +EOF + #t # set partition type + #1 # on partition 1 + #4 # BIOS boot + +# Format and mount partitions +mkfs.ext4 "${disk}1" + +mount "${disk}1" /mnt + +# Bootstrap system +pacstrap -K /mnt base linux nano sudo networkmanager openssh grub python3 +genfstab -L /mnt >> /mnt/etc/fstab + +# Run stuff in the chroot +curl -o /mnt/in-chroot.sh http://10.0.2.2:"${port}"/in-chroot.sh +arch-chroot /mnt /usr/bin/bash /in-chroot.sh "${disk}" +rm /mnt/in-chroot.sh + +reboot diff --git a/distros/arch/2023.08.01/http/ks.cfg b/distros/arch/2023.08.01/http/ks.cfg new file mode 100644 index 0000000..afa2211 --- /dev/null +++ b/distros/arch/2023.08.01/http/ks.cfg @@ -0,0 +1,54 @@ +install +text +reboot +network --bootproto=dhcp --activate +url --url=http://mirror.centos.org/centos/7/os/x86_64/ +repo --name=updates --baseurl=http://mirror.centos.org/centos/7/updates/x86_64/ +lang en_US.UTF-8 +keyboard us +timezone --utc Etc/UTC +rootpw --plaintext vagrant +user --name=vagrant --groups=vagrant --password=vagrant --plaintext +zerombr +clearpart --all --initlabel +autopart --type=plain +bootloader --timeout=1 + +%packages +@core +which +libselinux-python +# mandatory packages in the @core group +-btrfs-progs +-iprutils +-kexec-tools +-plymouth +# default packages in the @core group +-*-firmware +-dracut-config-rescue +-kernel-tools +-libsysfs +-microcode_ctl +-NetworkManager* +-postfix +-rdma +%end + +%post --erroronfail +yum -y update + +cat < /etc/sudoers.d/vagrant +Defaults:vagrant !requiretty +vagrant ALL=(ALL) NOPASSWD: ALL +EOF +chmod 440 /etc/sudoers.d/vagrant + +ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules +cat > /etc/sysconfig/network-scripts/ifcfg-eth0 < net.ifnames=0 biosdevnames=0", + "", # Wait for system to come up? + "curl -o /tmp/install.sh http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.sh", + "", + "/usr/bin/bash /tmp/install.sh {{ .HTTPPort }}" +] +http_directory = "distros/arch/2023.08.01/http/" +boot_wait = "10s" diff --git a/distros/arch/supports.yml b/distros/arch/supports.yml new file mode 100644 index 0000000..4b2a349 --- /dev/null +++ b/distros/arch/supports.yml @@ -0,0 +1,5 @@ +2023.08.01: +- arch: x86_64 + provider: qemu +- arch: x86_64 + provider: virtualbox-iso diff --git a/test.xsh b/test.xsh index c470e4e..1ce83c8 100755 --- a/test.xsh +++ b/test.xsh @@ -54,10 +54,8 @@ def main(): for box in g`output/**/*.box`: p = pathlib.Path(box) sed -e f's#@@BOX@@#file:///home/greg/src/vms/vms/{box}#' -e f's/@@BOX_NAME@@/{p.name}/' Vagrantfile.in > Vagrantfile - if str(p.parent.name) == "virtualbox": - vagrant up --provider virtualbox - elif str(p.parent.name) == "qemu": - vagrant up --provider libvirt + if str(p.parent.name) in ["virtualbox", "libvirt"]: + vagrant up --provider @(p.parent.name) else: print(f"Now whatcha wanna go and do that for? {box}") continue