Skip to content

Instantly share code, notes, and snippets.

@imduffy15
Last active April 9, 2024 07:15
Show Gist options
  • Save imduffy15/2d6f3cd46efa2ff68286 to your computer and use it in GitHub Desktop.
Save imduffy15/2d6f3cd46efa2ff68286 to your computer and use it in GitHub Desktop.
Cloud-init config example for using the none data source provider to setup a box for usage with vagrant on finding no cloud metadata service.
disable_ec2_metadata: True
datasource_list: [ "ConfigDrive", "None"]
datasource:
None:
userdata_raw: |
#!/bin/bash
groupadd vagrant
useradd -d /home/vagrant -s /bin/bash -m -g vagrant -G wheel vagrant
echo "root:vagrant" | chpasswd
echo "vagrant:vagrant" | chpasswd
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
chmod 0440 /etc/sudoers.d/vagrant
# set a default HOME_DIR environment variable if not set
HOME_DIR="${HOME_DIR:-/home/vagrant}";
mkdir -p $HOME_DIR/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > $HOME_DIR/.ssh/authorized_keys
chown -R vagrant $HOME_DIR/.ssh;
chmod -R go-rwsx $HOME_DIR/.ssh;
metadata:
instance-id: vagrant
local-hostname: vagrant.localdomain
@mkesper
Copy link

mkesper commented Sep 13, 2021

Many of the optiions can be set declaratively, without involving shell scripting: https://cloudinit.readthedocs.io/en/latest/topics/examples.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment