首页 > 解决方案 > Cloudinit 能否用于自动化复杂的配置,例如 UFW 和 Apache

问题描述

Cloudinit 可以处理基本配置,例如创建用户和组、安装包、挂载存储点等(请参阅Cloud Config 示例)。但是它可以处理像下面这样更复杂的任务吗?如果可以,如何处理?一个最小的工作示例将不胜感激。

 # 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"      

标签: bashcloud-init

解决方案


如果您专门指的是cloud-config,那么您列出的所有未知数都没有针对它们的特定模块。但是,您也可以通过runcmd模块运行任意 shell 脚本,或者将脚本指定为用户数据而不是云配置。它只需要从而#!不是开始#cloud-config。如果您需要云配置和自定义 shell 脚本,可以使用 cloud-init 辅助命令构建mime 多部分存档。


推荐阅读