diff --git a/stage2/02-cloud-init/00-packages b/stage2/02-cloud-init/00-packages new file mode 100644 index 0000000..f604b82 --- /dev/null +++ b/stage2/02-cloud-init/00-packages @@ -0,0 +1,2 @@ +cloud-init +ssh-import-id diff --git a/stage2/02-cloud-init/01-run.sh b/stage2/02-cloud-init/01-run.sh new file mode 100644 index 0000000..8bf2111 --- /dev/null +++ b/stage2/02-cloud-init/01-run.sh @@ -0,0 +1,20 @@ +#!/bin/bash -e + +install -m 644 files/user-data ${ROOTFS_DIR}/boot/ +install -m 644 files/meta-data ${ROOTFS_DIR}/boot/ +install -m 644 files/cloud/cloud.cfg ${ROOTFS_DIR}/etc/cloud/ + +on_chroot << EOF +echo 'Get cloud-init' + +echo 'Symlinking cloud-init nocloud-net seed files to /boot partition' +mkdir -p /var/lib/cloud/seed/nocloud-net +if [ ! -f /var/lib/cloud/seed/nocloud-net/user-data ] +then + ln -s /boot/user-data /var/lib/cloud/seed/nocloud-net/user-data +fi +if [ ! -f /var/lib/cloud/seed/nocloud-net/meta-data ] +then + ln -s /boot/meta-data /var/lib/cloud/seed/nocloud-net/meta-data +fi +EOF diff --git a/stage2/02-cloud-init/files/cloud/cloud.cfg b/stage2/02-cloud-init/files/cloud/cloud.cfg new file mode 100644 index 0000000..63ba4c3 --- /dev/null +++ b/stage2/02-cloud-init/files/cloud/cloud.cfg @@ -0,0 +1,187 @@ +# The top level settings are used as module +# and system configuration. + +# A set of users which may be applied and/or used by various modules +# when a 'default' entry is found it will reference the 'default_user' +# from the distro configuration specified below +users: + - default + +# If this is set, 'root' will not be able to ssh in and they +# will get a message to login instead as the above $user (debian) +disable_root: true + +# This will cause the set+update hostname module to not operate (if true) +preserve_hostname: false + +# This preserve the sources list +apt_preserve_sources_list: true + +datasource_list: [ NoCloud ] + +# Example datasource config +#datasourcef: +# Ec2: +# metadata_urls: [ 'blah.com' ] +# timeout: 5 # (defaults to 50 seconds) +# max_wait: 10 # (defaults to 120 seconds) + +# The modules that run in the 'init' stage +cloud_init_modules: + # migrate old versions of cloud-init data to new + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#migrator + - migrator + # provide random seed data + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#seed-random + - seed_random + # Run arbitrary commands early in the boot process + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#bootcmd + - bootcmd + # write arbitrary files + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#write-files + - write-files + # grow partitions + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#growpart + - growpart + # Resize filesystem + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#resizefs + - resizefs + # configure partitions and filesystems + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#disk-setup + - disk_setup + # configure mount points and swap files + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#mounts + - mounts + # set hostname and fqdn + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#set-hostname + - set_hostname + # update hostname and fqdn + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#update-hostname + - update_hostname + # update /etc/hosts + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#update-etc-hosts + - update_etc_hosts + # add ca certificates + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#ca-certs + - ca-certs + # configure system loggig via rsyslog + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#rsyslog + - rsyslog + # configure users and groups + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#users-and-groups + - users-groups + # configure ssh and ssh keys + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#ssh + - ssh + +# The modules that run in the 'config' stage +cloud_config_modules: +# Emit the cloud config ready event +# this can be used by upstart jobs for 'start on cloud-config'. + # emit upstart configuration + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#emit-upstart + - emit_upstart + # import ssh id + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#ssh-import-id + - ssh-import-id + # set system locale + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#locale + - locale + # Set user passwords + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#set-passwords + - set-passwords + # configure grub debconf installation device + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#grub-dpkg + - grub-dpkg + # configure apt pipelining + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#apt-pipelining + - apt-pipelining + # configure apt + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#apt-configure + - apt-configure + # enable and configure ntp + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#ntp + - ntp + # set system timezone + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#timezone + - timezone + # disable aws ec2 metadata + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#disable-ec2-metadata + - disable-ec2-metadata + # Run arbitrary commands + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#runcmd + - runcmd + # enable/disable byobu system wide and for default user + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#byobu + - byobu + +# The modules that run in the 'final' stage +cloud_final_modules: + # update, upgrade, and install packages + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#package-update-upgrade-install + - package-update-upgrade-install + # configure ubuntu fan networking + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#fan + - fan + # install, configure and start puppet + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#puppet + - puppet + # module that configures, starts and installs chef. + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#chef + - chef + # set up and run salt minion + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#salt-minion + - salt-minion + # install, configure and start mcollective + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#mcollective + - mcollective + # support rightscale configuration hooks + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#rightscale-userdata + - rightscale_userdata + # run vendor scripts + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#scripts-vendor + - scripts-vendor + # run one time scripts + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#scripts-per-once + - scripts-per-once + # run per boot scripts + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#scripts-per-boot + - scripts-per-boot + # run per instance scripts + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#scripts-per-instance + - scripts-per-instance + # run user scripts + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#scripts-user + - scripts-user + # log fingerprints of user ssh keys + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#ssh-authkey-fingerprints + - ssh-authkey-fingerprints + # control which ssh keys may be written to console + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#keys-to-console + - keys-to-console + # post data to url + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#phone-home + - phone-home + # output final message when cloud-init has finished + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#final-message + - final-message + # change power state + # https://cloudinit.readthedocs.io/en/18.3/topics/modules.html#power-state-change + - power-state-change + +# System and/or distro specific settings +# (not accessible to handlers/transforms) +system_info: + # This will affect which distro class gets used + distro: debian + # Default user name + that default users groups (if added/used) + default_user: + name: pi + #lock_passwd: True + shell: /bin/bash + # Other config here will be given to the distro class and/or path classes + paths: + cloud_dir: /var/lib/cloud/ + templates_dir: /etc/cloud/templates/ + upstart_dir: /etc/init/ + ssh_svcname: ssh diff --git a/stage2/02-cloud-init/files/meta-data b/stage2/02-cloud-init/files/meta-data new file mode 100644 index 0000000..bbb093d --- /dev/null +++ b/stage2/02-cloud-init/files/meta-data @@ -0,0 +1 @@ +instance-id: iid-raspberrypi-nocloud diff --git a/stage2/02-cloud-init/files/user-data b/stage2/02-cloud-init/files/user-data new file mode 100644 index 0000000..6514159 --- /dev/null +++ b/stage2/02-cloud-init/files/user-data @@ -0,0 +1,63 @@ +#cloud-config +# vim: syntax=yaml +# + +# The current version of cloud-init in the Hypriot rpi-64 is 0.7.6 +# When dealing with cloud-init, it is SUPER important to know the version +# I have wasted many hours creating servers to find out the module I was trying to use wasn't in the cloud-init version I had +# Documentation: http://cloudinit.readthedocs.io/en/0.7.9/index.html + +# Set your hostname here, the manage_etc_hosts will update the hosts file entries as well +#hostname: raspberrypi +#manage_etc_hosts: true + +# You could modify this for your own user information +#users: +# - default + +# # Set the locale of the system +# locale: "en_US.UTF-8" + +# # Set the timezone +# # Value of 'timezone' must exist in /usr/share/zoneinfo +# timezone: "America/Los_Angeles" + +# # Update apt packages on first boot +# package_update: true +# package_upgrade: true +# package_reboot_if_required: true +package_upgrade: false + +# # Install any additional apt packages you need here +# packages: +# - ntp + +# # WiFi connect to HotSpot +# # - use `wpa_passphrase SSID PASSWORD` to encrypt the psk +# write_files: +# - content: | +# allow-hotplug wlan0 +# iface wlan0 inet dhcp +# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf +# iface default inet dhcp +# path: /etc/network/interfaces.d/wlan0 +# - content: | +# ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev +# update_config=1 +# network={ +# ssid="YOUR_WIFI_SSID" +# psk="YOUR_WIFI_PASSWORD" +# proto=RSN +# key_mgmt=WPA-PSK +# pairwise=CCMP +# auth_alg=OPEN +# } +# path: /etc/wpa_supplicant/wpa_supplicant.conf + +# These commands will be ran once on first boot only +runcmd: + # Pickup the hostname changes + #- 'systemctl restart avahi-daemon' + +# # Activate WiFi interface +# - 'ifup wlan0'