bash - 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"
解决方案
如果您专门指的是cloud-config,那么您列出的所有未知数都没有针对它们的特定模块。但是,您也可以通过runcmd模块运行任意 shell 脚本,或者将脚本指定为用户数据而不是云配置。它只需要从而#!
不是开始#cloud-config
。如果您需要云配置和自定义 shell 脚本,可以使用 cloud-init 辅助命令构建mime 多部分存档。
推荐阅读
- php - 计算引擎 | LSB 启动失败:Treasure Data 的数据采集器
- django - 不同模型的Django模型
- c# - ML.NET 张量流 half_plus_two
- javascript - 如何在 Reactjs 应用程序中使用分页
- node.js - 使用 NodeJS/Typescript 在控制台中的打字机效果
- r - 用不同的模式替换文本
- javascript - 如何从 Puppeteer 将文本输入到 Flash TextArea 中?
- cadence-workflow - 从 Cadence 工作流程和活动记录消息的最佳方式是什么?
- json - 你如何编码 WIQL JSON?
- javascript - 替代正面看背后