[iyunv@sh-proxy2 local]# puppet describe host
host
====
Installs and manages host entries. For most systems, these
entries will just be in `/etc/hosts`, but some systems (notably OS X)
will have different solutions.
Parameters
----------
- **comment**
A comment that will be attached to the line with a # character.
- **ensure**
The basic property that the resource should be in.
Valid values are `present`, `absent`.
- **host_aliases**
Any aliases the host might have. Multiple values must be
specified as an array.
- **ip**
The host's IP address, IPv4 or IPv6.
- **name**
The host name.
- **target**
The file in which to store service information. Only used by
those providers that write to disk. On most systems this defaults to
`/etc/hosts`.
Providers
---------
parsed
host资源常用的属性:
host {"资源标题":
ensure
ip
name
host_aliases
target
}
class admin {
include admin::hosts
exec {"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文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class admin::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 {"test.example.com":
ensure => present,
host_aliases => ["db","web"],
ip => "192.168.30.137",
}
}
puppet 入口文件nodes.pp所有主机都继承admin.
说明:nodes.pp文件内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
node base {
include admin
}
node /sh-(proxy|web)\d+/ inherits base {
case $::hostname {
/sh-proxy\d+/: {
include nginx
}
"sh-web1": {
include cron
}
}
}
说明:下面的更新是没有加"host_aliases"别名的更新,为了区别别名效果.
1
2
3
4
5
6
7
8
9
10
[iyunv@sh-proxy2 local]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for sh-proxy2.localdomain
Info: Applying configuration version '1507646562'
Notice: /Stage[main]/Admin/Exec[selinux]/returns: executed successfully
Notice: /Stage[main]/Admin::Hosts/Host[test.example.com]/ensure: created
Info: Computing checksum on file /etc/hosts
Notice: Finished catalog run in 0.23 seconds
1
2
3
4
5
6
7
8
9
10
[iyunv@sh-proxy2 local]# cat /etc/hosts
# HEADER: This file was autogenerated at Tue Oct 10 22:42:50 +0800 2017
# HEADER: by puppet. While it can still be managed manually, it
# HEADER: is definitely not recommended.
127.0.0.1localhostlocalhost.localdomain localhost4 localhost4.localdomain4
::1localhostlocalhost.localdomain localhost6 localhost6.localdomain6
192.168.30.134puppet
192.168.30.131sh-web1
192.168.30.132sh-proxy2
192.168.30.137test.example.com
说明:下面的更新是加了"host_aliases"别名的更新,为了区别别名效果.
1
2
3
4
5
6
7
8
9
10
[iyunv@sh-proxy2 local]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for sh-proxy2.localdomain
Info: Applying configuration version '1507646705'
Notice: /Stage[main]/Admin/Exec[selinux]/returns: executed successfully
Notice: /Stage[main]/Admin::Hosts/Host[test.example.com]/host_aliases: defined 'host_aliases' as 'db web'
Info: Computing checksum on file /etc/hosts
Notice: Finished catalog run in 0.23 seconds
1
2
3
4
5
6
7
8
9
10
[iyunv@sh-proxy2 local]# cat /etc/hosts
# HEADER: This file was autogenerated at Tue Oct 10 22:45:07 +0800 2017
# HEADER: by puppet. While it can still be managed manually, it
# HEADER: is definitely not recommended.
127.0.0.1localhostlocalhost.localdomain localhost4 localhost4.localdomain4
::1localhostlocalhost.localdomain localhost6 localhost6.localdomain6
192.168.30.134puppet
192.168.30.131sh-web1
192.168.30.132sh-proxy2
192.168.30.137test.example.comdb web