puppet寫ntp模塊

實驗1 ntpd的部署

實驗基本環境

debian7

三臺主機(沒有域,已經做好認證)

debian(master 2.7.23,debian7),liuliancao(agent 2.7.23,debian7),luqixue(agent,3.6.2,Centos 7)

debian master寫模塊

root@debian:/etc/puppet/modules# mkdir -p ntp/{manifests,files,templates}root@debian:/etc/puppet# cat modules/ntp/manifests/init.pp # Class:  ntp## This class installs/configures/manages NTP. Only Debian-derived and RedHat-derived are supported.## Parameters:#   -$servers:#       An array of ntp servers.Default to OS's defaults.  #   -$enable:#       Whether to start the NTP service on boot.Valid values are:#       true and false.#   -$ensure:#       Whether to run the NTP service.Valid values are:#       running and stopped.# Requires:#   Nothing.## Sample Usage:## class {'ntp':#   server  =>  ['0.cn.pool.ntp.org',#                '1.cn.pool.ntp.org',#               ]# }# class {'ntp':#   enable  =>  false,#   ensure  =>  stopped,# }class ntp ($servers = undef, $enable = true, $ensure = running) {    case $operatingsystem {
       centos,redhat:  {            $service_name   =   'ntpd'
            $service_conf   =   'ntp.conf.e1.erb'
            $default_servers=   ['0.centos.pool.ntp.org',                                 '1.centos.pool.ntp.org',                                 '2.centos.pool.ntp.org',
                                ]
        }       debian: {            $service_name   =   'ntp'
            $service_conf   =   'ntp.conf.debian.erb'
            $default_servers=   ['0.debian.pool.ntp.org',                                 '1.debian.pool.ntp.org',                                 '2.debian.pool.ntp.org',
                                ]
       }
    }
    
    if $servers == undef {        $servers_real   =   $default_servers
    }
    else {        $servers_real   =   $servers
    }

    package {'ntp': ensure  =>  installed} 
    service {$service_name:
        ensure  =>  $ensure,
        enable  =>  $enable,
        subscribe=> File['/etc/ntp.conf'],
    }
    file {'/etc/ntp.conf':
        ensure  =>  file,
        require =>  Package['ntp'],
        content =>  template("ntp/${service_conf}"),
    }
}

root@debian:/etc/puppet# cat modules/ntp/templates/ntp.conf.debian.erb # /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for helpdriftfile /var/lib/ntp/ntp.drift# Enable this if you want statistics to be logged.#statsdir /var/log/ntpstats/statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable# You do need to talk to an NTP server or two (or three).#server ntp.your-provider.example# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will# pick a different set every time it starts up.  Please consider joining the# pool: <http://www.pool.ntp.org/join.html># server 0.debian.pool.ntp.org iburst# server 1.debian.pool.ntp.org iburst# server 2.debian.pool.ntp.org iburst# server 3.debian.pool.ntp.org iburst# 這裏是我添加的部分,注意不需要加$<% servers_real.each do |server| -%>
server <%= server %>
<% end -%># Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for# details.  The web page <http://support.ntp.org/bin/view/Support/Acce***estrictions># might also be helpful.## Note that "restrict" applies to both servers and clients, so a configuration# that might be intended to block requests from certain clients could also end# up blocking replies from your own upstream servers.# By default, exchange time with everybody, but don't allow configuration.restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery# Local users may interrogate the ntp server more closely.restrict 127.0.0.1restrict ::1# Clients from this (example!) subnet have unlimited access, but only if# cryptographically authenticated.#restrict 192.168.123.0 mask 255.255.255.0 notrust# If you want to provide time to your local subnet, change the next line.# (Again, the address is an example only.)#broadcast 192.168.123.255# If you want to listen to time broadcasts on your local subnet, de-comment the# next lines.  Please do this only if you trust everybody on the network!#disable auth#broadcastclient# 最後去清單文件包含這個模塊ntproot@debian:/etc/puppet# cat manifests/nodes/liuliancao.ppnode 'liuliancao' {    include ntp
}

debian客戶端liuliancao執行:

root@liuliancao:~# puppet agent --test --verbose --server debianinfo: Caching catalog for liuliancao
info: Applying configuration version '1468658530'notice: /Stage[main]/Ntp/File[/etc/ntp.conf]/content: 
--- /etc/ntp.conf	2015-10-29 04:18:49.000000000 +0800+++ /tmp/puppet-file20160716-11940-birtla-0	2016-07-16 16:42:11.044269965 +0800@@ -18,10 +18,13 @@ # pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
 # pick a different set every time it starts up.  Please consider joining the
 # pool: <http://www.pool.ntp.org/join.html>-server 0.debian.pool.ntp.org iburst
-server 1.debian.pool.ntp.org iburst
-server 2.debian.pool.ntp.org iburst
-server 3.debian.pool.ntp.org iburst
+# server 0.debian.pool.ntp.org iburst+# server 1.debian.pool.ntp.org iburst+# server 2.debian.pool.ntp.org iburst+# server 3.debian.pool.ntp.org iburst+server 0.debian.pool.ntp.org
+server 1.debian.pool.ntp.org
+server 2.debian.pool.ntp.org 
 
 # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html forinfo: FileBucket adding {md5}3e250ecaf470e1d3a2b68edd5de46bfd
info: /Stage[main]/Ntp/File[/etc/ntp.conf]: Filebucketed /etc/ntp.conf to puppet with sum 3e250ecaf470e1d3a2b68edd5de46bfd
notice: /Stage[main]/Ntp/File[/etc/ntp.conf]/content: content changed '{md5}3e250ecaf470e1d3a2b68edd5de46bfd' to '{md5}17d90ad4446c8cb6c232e81839950046'info: /Stage[main]/Ntp/File[/etc/ntp.conf]: Scheduling refresh of Service[ntp]
notice: /Stage[main]/Ntp/Service[ntp]: Triggered 'refresh' from 1 events
notice: Finished catalog run in 0.19 seconds

把master中的關於liuliancao的清單文件修改了一下

root@debian:/etc/puppet# cat manifests/nodes/liuliancao.ppnode 'liuliancao' {   class {'ntp':
        enable  =>  false,        ensure  =>  stopped,
    }
}

這個時候liuliancao端再進行同步發現

root@liuliancao:~# puppet agent --test --verbose --server debianinfo: Caching catalog for liuliancao
info: Applying configuration version '1468658966'notice: /Stage[main]/Ntp/Service[ntp]/ensure: ensure changed 'running' to 'stopped'notice: Finished catalog run in 0.17 seconds

另一臺機器,也一樣奏效了,主文件的清單

root@debian:/etc/puppet# cat manifests/nodes/luqixue.ppnode 'luqixue'  {    class {'ntp':
        enable  =>  false,        ensure  =>  stopped,
    }
}

客戶機luqixue執行的結果反饋:由於我版本兼容性問題,所以前面報錯,忽略不計哈

[root@luqixue ~]# puppet agent --test --verbose --server debianNotice: Using less secure serialization of reports and query parameters for compatibilityNotice: with older puppet master. To remove this notice, please upgrade your master(s) 
Notice: to Puppet 3.3 or newer.Notice: See http://links.puppetlabs.com/deprecate_yaml_on_network for more information.Info: Retrieving pluginfactsError: /File[/var/lib/puppet/facts.d]: Failed to generate additional resources using 'eval_generate': Error 400 on SERVER: Not authorized to call search on /file_metadata/pluginfacts with {:checksum_type=>"md5", :links=>"manage", :ignore=>[".svn", "CVS", ".git"], :recurse=>true}Error: /File[/var/lib/puppet/facts.d]: Could not evaluate: Could not retrieve file metadata for puppet://debian/pluginfacts: Error 400 on SERVER: Not authorized to call find on /file_metadata/pluginfacts with {:links=>"manage", :source_permissions=>"use"}Wrapped exception:Error 400 on SERVER: Not authorized to call find on /file_metadata/pluginfacts with {:links=>"manage", :source_permissions=>"use"}Info: Retrieving pluginError: /File[/var/lib/puppet/lib]: Could not evaluate: Could not retrieve information from environment production source(s) puppet://debian/pluginsInfo: Caching catalog for luqixueWarning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
   (at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')Warning: Local environment: "production" doesn't match server specified environment "none", restarting agent run with environment "none"Info: Caching catalog for luqixueInfo: Applying configuration version '1468659466'Notice: /Stage[main]/Ntp/Package[ntp]/ensure: createdNotice: /Stage[main]/Ntp/File[/etc/ntp.conf]/content: 
--- /etc/ntp.conf	2016-05-31 06:11:10.000000000 -0400+++ /tmp/puppet-file20160715-11400-c9j0hl	2016-07-15 20:51:19.148127365 -0400@@ -18,16 +18,20 @@ 
 # Use public servers from the pool.ntp.org project.
 # Please consider joining the pool (http://www.pool.ntp.org/join.html).-server 0.centos.pool.ntp.org iburst
-server 1.centos.pool.ntp.org iburst
-server 2.centos.pool.ntp.org iburst
-server 3.centos.pool.ntp.org iburst
-
-#broadcast 192.168.1.255 autokey	# broadcast server-#broadcastclient			# broadcast client-#broadcast 224.0.1.1 autokey		# multicast server-#multicastclient 224.0.1.1		# multicast client-#manycastserver 239.255.254.254		# manycast server+# server 0.centos.pool.ntp.org iburst+# server 1.centos.pool.ntp.org iburst+# server 2.centos.pool.ntp.org iburst+# server 3.centos.pool.ntp.org iburst+server 0.centos.pool.ntp.org
+server 1.centos.pool.ntp.org
+server 2.centos.pool.ntp.org
+
+
+#broadcast 192.168.1.255 autokey    # broadcast server+#broadcastclient            # broadcast client+#broadcast 224.0.1.1 autokey        # multicast server+#multicastclient 224.0.1.1      # multicast client+#manycastserver 239.255.254.254     # manycast server
 #manycastclient 239.255.254.254 autokey # manycast client
 
 # Enable public key cryptography.@@ -56,3 +60,4 @@ # CVE-2013-5211 for more details.
 # Note: Monitoring will not be disabled with the limited restriction flag.
 disable monitor
+Info: /Stage[main]/Ntp/File[/etc/ntp.conf]: Filebucketed /etc/ntp.conf to puppet with sum dc9e5754ad2bb6f6c32b954c04431d0aNotice: /Stage[main]/Ntp/File[/etc/ntp.conf]/content: content changed '{md5}dc9e5754ad2bb6f6c32b954c04431d0a' to '{md5}caa18108d6b812d165eb605060a48b39'Info: /Stage[main]/Ntp/File[/etc/ntp.conf]: Scheduling refresh of Service[ntpd]Notice: /Stage[main]/Ntp/Service[ntpd]: Triggered 'refresh' from 1 eventsNotice: Finished catalog run in 8.51 seconds


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章