agent向server拉取文件,进行同步。需要对server进行配置。
假如将server侧的/etc/httpd/conf/httpd.conf同步到agent。server侧/etc/puppet/manifests/site.pp内容如下:file后的“/etc/httpd/conf/httpd.conf”为agent侧的位置,source后为准备同步下去的文件在master服务器上的位置
。
node default {
notify{"Hello World":
name => "welcome",
message => "Hello World!",
}
file {"/etc/httpd/conf/httpd.conf":
mode => '777',owner => 'nobody',group => 'nobody',
backup => '.bak',
source => "puppet:///mount_point/httpd.conf",
}
}
在/etc/puppet/fileserver.conf的最后添加mount_point的配置,如下:
[root@puppetmaster puppet]# tail fileserver.conf
# allow /^(.+)\.example\.com$/
# allow_ip 192.168.100.0/24
#
# If added to auth.conf BEFORE the "path /file" rule, the rule above
# will add stricter restrictions to the extra_files mount point.
#
[mount_point]
path /etc/httpd/conf
allow *
在agent端验证(生成了.bak文件,也有hello world的输出):
[root@puppetclient2 puppet]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppetclient2
Info: Applying configuration version '1551258710'
Notice: /Stage[main]/Main/Node[default]/File[/etc/httpd/conf/httpd.conf]/content:
--- /etc/httpd/conf/httpd.conf 2018-02-19 19:24:50.000000000 +0800
+++ /tmp/puppet-file20190227-17325-bv4h7t-0 2019-02-27 17:12:15.123457239 +0800
@@ -1,4 +1,6 @@
#
+#haha
+#
# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2/> for detailed information.
Notice: /Stage[main]/Main/Node[default]/File[/etc/httpd/conf/httpd.conf]/content: content changed '{md5}f6351c6d8c8dfc5899820d8c46d74651' to '{md5}60f4b8ee93f4a19994aa94395dfe6812'
Notice: /Stage[main]/Main/Node[default]/File[/etc/httpd/conf/httpd.conf]/owner: owner changed 'root' to 'nobody'
Notice: /Stage[main]/Main/Node[default]/File[/etc/httpd/conf/httpd.conf]/group: group changed 'root' to 'nobody'
Notice: /Stage[main]/Main/Node[default]/File[/etc/httpd/conf/httpd.conf]/mode: mode changed '0644' to '0777'
Notice: Hello World!
Notice: /Stage[main]/Main/Node[default]/Notify[Hello World]/message: defined 'message' as 'Hello World!'
Notice: Finished catalog run in 0.20 seconds
[root@puppetclient2 puppet]# ll /etc/httpd/conf/httpd.conf.bak
-rw-r--r-- 1 root root 34419 Feb 19 2018 /etc/httpd/conf/httpd.conf.bak
如果遇到故障,一定要冷静思考。如果认证什么都正常,但是agent不报错,但无法同步,就需要检查server侧的配置文件,环境了。