失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Puppet Host资源介绍(二十一)

Puppet Host资源介绍(二十一)

时间:2021-02-21 20:25:47

相关推荐

Puppet Host资源介绍(二十一)

puppet host资源

host资源主要用来管理操作系统的hosts功能,hosts是一个没有扩展名的系统文件,基本作用就是关联ip和域名,当用户打开一个网址会首先从hosts解析,如果没有再去dns查找解析.linux系统存放在/etc/hosts文件中。

使用puppet describe host查看资源帮助信息:

[root@sh-proxy2local]#puppetdescribehosthost====Installsandmanageshostentries.Formostsystems,theseentrieswilljustbein`/etc/hosts`,butsomesystems(notablyOSX)willhavedifferentsolutions.Parameters-----------**comment**Acommentthatwillbeattachedtothelinewitha#character.-**ensure**Thebasicpropertythattheresourceshouldbein.Validvaluesare`present`,`absent`.-**host_aliases**Anyaliasesthehostmighthave.Multiplevaluesmustbespecifiedasanarray.-**ip**Thehost'sIPaddress,IPv4orIPv6.-**name**Thehostname.-**target**Thefileinwhichtostoreserviceinformation.Onlyusedbythoseprovidersthatwritetodisk.Onmostsystemsthisdefaultsto`/etc/hosts`.Providers---------parsed

host资源常用的属性:

host {"资源标题":

ensure

ip

name

host_aliases

target

}

资源参数意义:

ensure:确定该主机是否启用,值为present即启用,值为absent即关闭.

ip:主机的ip,支持ipv6.

name:主机名.

target:指定自定义host文件位置.

依旧使用old 三台机器演示:

192.168.30.134 puppet

192.168.30.131 sh-web1(web用途)

192.168.30.132 sh-proxy2(proxy)

之前文章写过定义admin模块为基础模块,所以将host资源加入admin模块即可使用。

说明:admin模块的init.pp文件声明admin::hosts类.

classadmin{includeadmin::hostsexec{"selinux":command=>"sed-i'/^SELINUX=/s/=.*/=disabled/g'/etc/sysconfig/selinux",path=>["/bin/","/sbin/","/usr/bin/","/usr/sbin/"],user=>root,group=>root,}}

说明:admin的manifests资源目录下新建hosts.pp文件:

classadmin::hosts{host{"puppet":ensure=>present,ip=>"192.168.30.134",}host{"sh-web1":ensure=>present,ip=>"192.168.30.131",}host{"sh-proxy2":ensure=>present,ip=>"192.168.30.132",}host{"":ensure=>present,host_aliases=>["db","web"],ip=>"192.168.30.137",}}

puppet 入口文件nodes.pp所有主机都继承admin.

说明:nodes.pp文件内容:

nodebase{includeadmin}node/sh-(proxy|web)\d+/inheritsbase{case$::hostname{/sh-proxy\d+/:{includenginx}"sh-web1":{includecron}}}

说明:下面的更新是没有加"host_aliases"别名的更新,为了区别别名效果.

[root@sh-proxy2local]#puppetagent-tInfo:RetrievingpluginfactsInfo:RetrievingpluginInfo:LoadingfactsInfo:Cachingcatalogforsh-proxy2.localdomainInfo:Applyingconfigurationversion'1507646562'Notice:/Stage[main]/Admin/Exec[selinux]/returns:executedsuccessfullyNotice:/Stage[main]/Admin::Hosts/Host[]/ensure:createdInfo:Computingchecksumonfile/etc/hostsNotice:Finishedcatalogrunin0.23seconds

[root@sh-proxy2local]#cat/etc/hosts#HEADER:ThisfilewasautogeneratedatTueOct1022:42:50+0800#HEADER:bypuppet.Whileitcanstillbemanagedmanually,it#HEADER:isdefinitelynotrecommended.127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6192.168.30.134puppet192.168.30.131sh-web1192.168.30.132sh-proxy2192.168.30.

说明:下面的更新是加了"host_aliases"别名的更新,为了区别别名效果.

[root@sh-proxy2local]#puppetagent-tInfo:RetrievingpluginfactsInfo:RetrievingpluginInfo:LoadingfactsInfo:Cachingcatalogforsh-proxy2.localdomainInfo:Applyingconfigurationversion'1507646705'Notice:/Stage[main]/Admin/Exec[selinux]/returns:executedsuccessfullyNotice:/Stage[main]/Admin::Hosts/Host[]/host_aliases:defined'host_aliases'as'dbweb'Info:Computingchecksumonfile/etc/hostsNotice:Finishedcatalogrunin0.23seconds

[root@sh-proxy2local]#cat/etc/hosts#HEADER:ThisfilewasautogeneratedatTueOct1022:45:07+0800#HEADER:bypuppet.Whileitcanstillbemanagedmanually,it#HEADER:isdefinitelynotrecommended.127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6192.168.30.134puppet192.168.30.131sh-web1192.168.30.132sh-proxy2192.168.30.dbweb

总结:其实方法不止这一种,hosts文件上篇写了file资源用法,可以直接写一个/etc/hosts file文件,所有主机下发这个文件也可以起到配置/etc/hosts的效果.

如果觉得《Puppet Host资源介绍(二十一)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。