$content="this is file"
file {"/tmp/text.txt":
ensure=> file,
content=> "$content",
}
$content="my name is lisi."
agent端更新会报错:
1
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Cannot reassign variable content at /etc/puppet/modules/admin/manifests/init.pp:13 on node sh-web1.localdomain
正确示例:
1
2
3
4
5
$content="this is file"
file {"/tmp/text.txt":
ensure=> file,
content=> "$content",
}
Agent端更新:
1
2
3
4
5
6
7
8
9
10
11
[iyunv@sh-web1 ~]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version '1505842152'
Notice: /Stage[main]/Admin/Exec[selinux]/returns: executed successfully
Notice: /Stage[main]/Admin/File[/tmp/text.txt]/ensure: defined content as '{md5}ee93ffc81f3898fcba28a1d0e72c0029'
Notice: Finished catalog run in 0.30 seconds
[iyunv@sh-web1 ~]# cat /tmp/text.txt
this is file
$content变量分别定义于top域、node域和local域.
示例:
$content="top"
node base {
include admin
$content="node"
}
node /sh-(proxy|web)\d+/ inherits base {
case $::hostname {
/sh-proxy\d+/: {
include apache
user {"test1":
ensure => present,
}
}
"sh-web1": {
include nginx::nginxconf
$content="sh-web1"
notify {"this value is $content":}
}
}
}
Agent端更新:
1
2
3
4
5
6
7
8
9
10
[iyunv@sh-web1 ~]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version '1505844151'
Notice: /Stage[main]/Admin/Exec[selinux]/returns: executed successfully
Notice: this value is sh-web1
Notice: /Stage[main]/Main/Node[sh-proxywebd]/Notify[this value is sh-web1]/message: defined 'message' as 'this value is sh-web1'
Notice: Finished catalog run in 0.25 seconds
$content="top"
node base {
include admin
$content="node"
}
node /sh-(proxy|web)\d+/ inherits base {
case $::hostname {
/sh-proxy\d+/: {
include apache
user {"test1":
ensure => present,
}
}
"sh-web1": {
include nginx::nginxconf
notify {"this value is $content":}
}
}
}
Agent端更新:
1
2
3
4
5
6
7
8
9
10
[iyunv@sh-web1 ~]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version '1505844281'
Notice: /Stage[main]/Admin/Exec[selinux]/returns: executed successfully
Notice: this value is node
Notice: /Stage[main]/Main/Node[sh-proxywebd]/Notify[this value is node]/message: defined 'message' as 'this value is node'
Notice: Finished catalog run in 0.26 seconds
notify {"this value is $content":}
node base {
include admin
$content="node"
}
node /sh-(proxy|web)\d+/ inherits base {
case $::hostname {
/sh-proxy\d+/: {
include apache
user {"test1":
ensure => present,
}
}
"sh-web1": {
include nginx::nginxconf
$content="sh-web1"
}
}
}
Agent端更新:
1
2
3
4
5
6
7
8
9
10
[iyunv@sh-web1 ~]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version '1505844582'
Notice: this value is
Notice: /Stage[main]/Main/Notify[this value is ]/message: defined 'message' as 'this value is '
Notice: /Stage[main]/Admin/Exec[selinux]/returns: executed successfully
Notice: Finished catalog run in 0.27 seconds
node base {
include admin
}
node /sh-(proxy|web)\d+/ inherits base {
case $::hostname {
/sh-proxy\d+/: {
include apache
user {"test1":
ensure => present,
}
}
"sh-web1": {
include nginx::nginxconf
notify {"hostip is $ipaddress_eth0":}
}
}
}
sh-web1 puppet agent端更新信息:
1
2
3
4
5
6
7
8
9
10
[iyunv@sh-web1 ~]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version '1505901622'
Notice: /Stage[main]/Admin/Exec[selinux]/returns: executed successfully
Notice: hostip is 192.168.30.131
Notice: /Stage[main]/Main/Node[sh-proxywebd]/Notify[hostip is 192.168.30.131]/message: defined 'message' as 'hostip is 192.168.30.131'
Notice: Finished catalog run in 0.27 seconds