我想使用Terraform创建一个AWS实例并在其中运行Puppet模块。我从github尝试过很多模块,似乎没什么用。有人试过吗?
答案 0 :(得分:3)
您基本上必须这样做的方法是使用remote-exec
配置程序在本地安装puppet,然后执行apply
或agent
。首先,像这样设置您的实例resource
:
resource "aws_instance" "instance_name" {
...
provisioner "remote-exec" {
script = "puppet.sh"
}
}
如果/不使用AWS(Azure,DO,GCE等),则为其他云提供商换出aws_instance
然后,使用该脚本安装Puppet,执行apply
或{{ 1}},然后卸载Puppet(如果你以后没有主动管理实例,你可能不会在云中)。
agent
这有一些变化。例如,您可以#!/bin/sh
# debian family example; swap out 'apt' and package names where necessary
# prep puppet
sudo apt-get update && sudo apt-get install ruby -y
sudo gem install --no-document puppet
# apply puppet
sudo puppet apply manifest.pp
# remove puppet
sudo gem uninstall -aIx
sudo apt-get remove ruby -y
sudo apt-get autoremove -y
针对您的Puppet Master或订阅Puppetlabs包存储库来安装Puppet AIO。您也可以在curl
后执行,而不是puppet agent -t
。这可能是优选的,因为将模块转移到与puppet apply
一起使用可能很麻烦。
答案 1 :(得分:0)
对于类似的用例,但使用ansible而不是puppet,我们使用null_resource和local-exec。
resource "null_resource" "lvm_housekeeping" {
triggers {
ebs_volume_ids = "${join(",", aws_volume_attachment.instance_ebs_attachment.*.volume_id)}"
}
provisioner "local-exec" {
command = "ANSIBLE_CONFIG=$HOME/'${var.ansible_repo_location}'/ansible.cfg ansible-playbook -u ec2-user -e target=all -i '${join(",",aws_instance.my_instance.*.private_ip)}, ' $HOME/'${var.ansible_repo_location}'/main.yml"
on_failure = "continue"
}
}