Last active
April 9, 2024 07:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Not referencing it just means use the default cloud-init ConfigDrive config if I remember correctly.
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
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