2

Cloudinit can handle basic configuration like creating users and groups, installing packages, mount storage points, and more (see Cloud Config Examples). But can it handle more complex tasks like the below, and if so, how? A minimal working example would be appreciated.

 # KNOWN: Replicating the below user creation with sudo privelges and a home                                    
 # directory is possible through cloudinit
 sudo adduser johnny
 sudo usermod -aG sudo johnny
 
 # KNOWN: Replicating the below public/private key creation is possible through
 # cloudinit
 ssh johny@10.0.0.1 "ssh-keygen -t rsa"
 
 # UNKNOWN: Is it possible to update the firewall rules in cloudinit or should
 # one simply SSH in afterwards like so
 ssh johnny@10.0.0.1 "
     sudo ufw enable
     sudo ufw allow http
     sudo ufw allow https"
 
 # UNKNOWN: Is it possible to deploy LetsEncrypt cetrificates or should one
 # simply SSH in afterwrds like so
 ssh johnny@10.0.0.1 "
     sudo service apache2 restart
     sudo certbot --apache"
 
 # UNKNOWN: Is it possible to clone and install git repositories or should one
 # simply SSH in afterwards like so
 ssh johnny@10.0.0.1 "
     GIT_NAME=johnny
     GIT_EMAIL=johnny.rico@citizen.federation
     git confing --global user.name $GIT_NAME
     git confing --global user.email $GIT_EMAIL
     git clone git@github.com:Federation:clandathu.git
     cd clandathu/install
     make --kill-em-all
     sudo make install"      

1 Answers1

2

If you're referring specifically to the cloud-config, then all of the unknowns that you have listed don't have specific modules for them. However, you can also run arbitrary shell scripts via the runcmd module, or by specifying a script as your user data instead of a cloud config. It just has to start with #! rather than #cloud-config. If you want both a cloud config and a custom shell script, you can build a mime multi part archive with a cloud-init helper command.

falcojr
  • 1,299
  • 1
  • 10
  • 18