Skip to content

Instantly share code, notes, and snippets.

@imduffy15
Last active April 9, 2024 07:15
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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
@bschonec
Copy link

bschonec commented Nov 12, 2019

Pardon the interruption but I've got a question regarding the use of datasource and datasource_list in your example above. What's the purpose of listing "ConfigDrive" on line #2 and then not referencing "ConfigDrive" in the datasource: (line 3) stanza? The reason that I ask is that I want to write a cloud-config file that will work with both VMware (AltCloud) and AWX (Ec2) datasources. I want to install a set of packages only when it's AltCloud and then a different set of packages only when it's Ec2. Is that even possible?

https://stackoverflow.com/questions/58738958/cloud-init-installing-a-different-package-based-on-the-datasource-thats-active

@imduffy15
Copy link
Author

Not referencing it just means use the default cloud-init ConfigDrive config if I remember correctly.

@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