Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cloud-config
- autoinstall:
- apt:
- disable_components: []
- fallback: abort
- geoip: true
- mirror-selection:
- primary:
- - country-mirror
- - arches: &id001
- - amd64
- - i386
- uri: http://archive.ubuntu.com/ubuntu/
- - arches: &id002
- - s390x
- - arm64
- - armhf
- - powerpc
- - ppc64el
- - riscv64
- uri: http://ports.ubuntu.com/ubuntu-ports
- preserve_sources_list: false
- security:
- - arches: *id001
- uri: http://security.ubuntu.com/ubuntu/
- - arches: *id002
- uri: http://ports.ubuntu.com/ubuntu-ports
- codecs:
- install: false
- drivers:
- install: false
- identity:
- hostname: localhost
- password: <scrubbed>
- realname: tux
- username: tux
- kernel:
- package: linux-generic
- keyboard:
- layout: us
- toggle: null
- variant: ''
- locale: en_US.UTF-8
- oem:
- install: auto
- source:
- id: ubuntu-server
- seiarch_drivers: false
- ssh:
- allow-pw: true
- authorized-keys: []
- install-server: true
- packages:
- - curl
- - ubuntu-desktop
- storage:
- config:
- # Partition table
- - { ptable: gpt, path: /dev/sda, wipe: superblock, preserve: false, name: '', grub_device: false, type: disk, id: disk-sda }
- # EFI boot partition
- - { device: disk-sda, size: 536870912, wipe: superblock, flag: boot, number: 1, preserve: false, grub_device: true, type: partition, id: partition-0 }
- - { fstype: fat32, volume: partition-0, preserve: false, type: format, id: format-0 }
- # Linux boot partition
- - { device: disk-sda, size: 1073741824, wipe: superblock, flag: '', number: 2, preserve: false, grub_device: false, type: partition, id: partition-1 }
- - { fstype: ext4, volume: partition-1, preserve: false, type: format, id: format-1 }
- # Partition for LVM, VG
- - { device: disk-sda, size: -1, wipe: superblock, flag: '', number: 3, preserve: false, grub_device: false, type: partition, id: partition-2 }
- - { name: vgroot, devices: [ partition-2 ], preserve: false, type: lvm_volgroup, id: lvm_volgroup-0 }
- # LV for var
- - { name: lvvar, volgroup: lvm_volgroup-0, size: 20G, wipe: superblock, preserve: false, type: lvm_partition, id: lvm_partition-0 }
- - { fstype: ext4, volume: lvm_partition-0, preserve: false, type: format, id: format-2 }
- # LV for root
- - { name: lvroot, volgroup: lvm_volgroup-0, size: 10G, wipe: superblock, preserve: false, type: lvm_partition, id: lvm_partition-2 }
- - { fstype: ext4, volume: lvm_partition-2, preserve: false, type: format, id: format-4 }
- # Mount points
- - { path: /boot, device: format-1, type: mount, id: mount-1 }
- - { path: /boot/efi, device: format-0, type: mount, id: mount-0 }
- - { path: /var, device: format-2, type: mount, id: mount-2 }
- - { path: /, device: format-4, type: mount, id: mount-4 }
- # Swapfile on root volume
- swap:
- swap: 5G
- updates: all
- version: 1
- write_files:
- - path: /etc/rc.local
- permissions: "0755"
- content: |
- #!/bin/bash
- # shellcheck disable=SC2181
- # --------------------------------------------------------------------------------
- # settings
- # --------------------------------------------------------------------------------
- set -u
- # --------------------------------------------------------------------------------
- # variables
- # --------------------------------------------------------------------------------
- webServer="<scrubbed>"
- webUrl="lxsetup/v1"
- bootStrap="bootstrap.sh"
- authToken="<scrubbed>"
- pid="$$"
- hostn=$(hostname)
- # --------------------------------------------------------------------------------
- # functions
- # --------------------------------------------------------------------------------
- fEcho() {
- logger --id ${pid} -t "rc.local" -s -p "local0.info" "$@"
- }
- # --------------------------------------------------------------------------------
- # main
- # --------------------------------------------------------------------------------
- # don't run, when we are called localhost
- #
- if [ "${hostn,,}" == "localhost" ]; then
- fEcho "WARNING: It seems, that we are still a template, or nobody gave us a name!"
- exit 0
- fi
- if [ ! -f "/etc/machine-id" ]; then
- fEcho "INFO: Regenerating machine ID"
- /usr/bin/systemd-machine-id-setup
- sync
- reboot
- else
- fEcho "INFO: Machine ID is present"
- fi
- # check that we have network connectivity and can ping the webserver
- #
- cnt=1
- maxRuns="50"
- while ! ping -q -c 1 -n -w 1 ${webServer} &>/dev/null; do
- fEcho "WARN: Can not reach the infra webserver: ${webServer} -- ${cnt} / ${maxRuns}"
- sleep 2
- # only go for 50 runs, then get out
- #
- if [ "${cnt}" -gt "${maxRuns}" ]; then
- fEcho "ERROR: stopping rc.local. Tried it now ${maxRuns} times!"
- ips=$(ip a)
- fEcho "ERROR: IP info: ${ips}"
- fEcho "ERROR: Going for a reboot in 5 min"
- shutdown -r +5m
- exit 1
- fi
- cnt=$((cnt+=1))
- done
- fEcho "INFO: reached the infra webserver: ${webServer}"
- # now get the bootstrap from our webserver
- #
- # -s keeps curl quiet by hiding progress meter and error messages
- # -S shows an error message if it fails (stderr)
- # -f Fail silently (no output at all) on server errors, keeping stdout clean
- # -o specifies an output file
- # -k unkown ssl-cert is ok
- # -H send header information
- #
- curl -s -S -f -k -H "Authorization: Basic ${authToken}" -o /tmp/${bootStrap} https://${webServer}/${webUrl}/${bootStrap}
- if [ "$?" -ne 0 ]; then
- fEcho "ERROR: Could not download the bootstrap file from ${webServer}"
- exit 1
- fi
- bash /tmp/${bootStrap}
- if [ "$?" -ne 0 ]; then
- fEcho "ERROR: Could not install puppet"
- exit 1
- fi
- rm /tmp/${bootStrap}
- if [ -f /etc/rc.local ]; then
- fEcho "INFO: Removing /etc/rc.local"
- rm /etc/rc.local
- fi
- sync
- sync
- fEcho "INFO: Everything went good, going for a reboot"
- sleep 1
- reboot
- late-commands:
- - chmod +x /etc/rc.local
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement