[英]Chef Recipe to set hostname of an EC2 instance AWS
I want to write a chef recipe that will set the hostname of the EC2 instance as : 我想写一个厨师食谱,将EC2实例的主机名设置为:
AWSRegionInstanceTyperandomNo
like awsedev001
像
awsedev001
how can I do this in a chef recipe? 我怎样才能在厨师食谱中做到这一点? Do we have any recipe for that ?
我们有什么食谱吗?
Please help 请帮忙
How would you do this in regular Unix land? 在常规的Unix领域,您将如何做到这一点?
You would first add the full FQDN to /etc/hostname
for persistence: 首先,您需要将完整的FQDN添加到
/etc/hostname
以便持久化:
file '/etc/hostname' do
content 'hostname.example.com'
end
Then you would set the hostname for the currently running os: 然后,您将为当前正在运行的操作系统设置主机名:
execute 'hostname hostname.example.com' do
not_if 'hostname -eq "hostname.example.com"'
end
This is a simple Chef recipe example, but it can be made more complex to suit your needs. 这是一个简单的Chef食谱示例,但可以使其更复杂以满足您的需求。 You may also want to look at the hostname cookbook on the Chef community site .
您可能还需要查看Chef社区网站上的主机名食谱 。
In AWS in order to change the hostname you need to edit 在AWS中以更改主机名需要编辑
/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=ip-172-16-1-23.ec2.internal
NOZEROCONF=yes
After editing the second line you can reboot and you are set. 编辑第二行后,您可以重新启动并设置好。
You can use the https://supermarket.chef.io/cookbooks/chef_hostname cookbook off of the community site. 您可以在社区站点之外使用https://supermarket.chef.io/cookbooks/chef_hostname食谱。
In your cookbook metadata.rb just declare: 在您的食谱metadata.rb中,只需声明:
depends "chef_hostname"
And then in your recipe code use the hostname resource to set the hostname: 然后在您的配方代码中,使用主机名资源设置主机名:
hostname "foo.example.com"
Or: 要么:
hostname node.name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.