天天看點

puppet agent向server拉取檔案進行同步

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的配置,如下:

[[email protected] 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的輸出):

[[email protected] 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
[[email protected] 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側的配置檔案,環境了。

繼續閱讀