Linux自动化运维之puppet的类和模块

摘要

类其实就是命名的puppet代码块,在需要是通过名称进行调用的一种管理机制很接近shell中的函数但是比shell的函数高级他是可以继承的。定义类的方式也很简单,我们只需使用所谓的class关键字来定义类就可以了。
到目前位置,我所做的资源申报不、定义类、声明类等所有的功能都只能在一个manifest文件中实现,但这却非是最有效的基于puppet管理IT基础架构的方式

一、puppet的类

class是用于通用目标的一组资源,因此他是命名的代码块,在某个位置创建之后可以在puppet全局使用

类可以放在模块中,通过声明的方式进行使用,而声明时通过include这么一个函数就可以实现,或者声明可以使用一个类似于资源申报语法一样的语法来使用。

类是用于通用目标的一组资源(只有在打算重复使用这段代码时才有必要声明成类),因此它是命名的代码块,在某个位置创建之后可以在puppet全局使用。

它类似与其他编程语言中类的功能,puppet的类可以被继承也可以包含子类。

类似于其他编程语言中中类的功能,puppet的class可以被继承,也可以包含子类

1、类的名称只能以小写字母开头,可以包含小写字母、数字和下划线

2、每个类都会引入一个新的变量作用域(scope),这意味着在任何时候访问类中的变量时,都得使用其完全限定名称(不过,在本地scope可以重新top scope中的变量赋予一个新值)

3、在manifest文件中定义的类不会直接被执行,它们需要实现声明后才能被执行(声明通常可以理解为调用)

4、调用类有以下4中方式

1)、使用include的方式调用,使用include关键字后面加上类名就可以(多个类可以用逗号分割)。(常用)

2)、使用require的方式调用,通常需要在指定的代码段的位置使用require指明调用那个class就可以了。(不常用)

3)、可以在声明一个类的时候像申报一个资源一样来调用一个类。(常用)

4)、使用ENC的机制来声明。

带参数类的使用:

同一个类在不同的OS上上可能会略有不同,因此需要通过获取相应系统的fact来实现有区别对待,然而万一相应的OS没有输出类所期望的fact或者是类依赖于非fact因素时,此机制将无法满足需求,此时就需要使用带参数的类来完成此类功能,在定义参数的类时,需要将参数声明在类名后的小括号内(参数可以有默认值,如果使用多个参数,彼此间要使用逗号分隔),在类的内部使用参数的方式同使用本地变量

类的继承:

1、继承资源属性

2、覆盖资源属性:(=>)

3、追加资源属性:(+>)

 

Linux自动化运维之puppet的类和模块

 

Linux自动化运维之puppet的类和模块

 

Linux自动化运维之puppet的类和模块

 

Linux自动化运维之puppet的类和模块

[root@Legion100 /tmp/puppet]# service mysqld stop
停止 mysqld:                                              [确定]
[root@Legion100 /tmp/puppet]# service httpd stop
停止 httpd:                                               [确定]
[root@Legion100 /tmp/puppet]# cat class.pp
class test {
        $webserver = $operatingsystem ? {
                /(?i-mx:ubuntu|debian)/ => 'apache2',
                /(?i-mx:centos|redhat)/ => 'httpd',
        }

        package {["$webserver","php","mysql-server"]:
                ensure  => present,
        }

        service {['mysqld',httpd]:
                ensure  => true,
                enable  => true,
        }
}

include test

[root@Legion100 /tmp/puppet]# puppet apply class.pp 2>/dev/null
Notice: Compiled catalog for legion100.dwhd.org in environment production in 0.36 seconds
Notice: /Stage[main]/Test/Service[httpd]/ensure: ensure changed 'stopped' to 'running'
Notice: /Stage[main]/Test/Service[mysqld]/ensure: ensure changed 'stopped' to 'running'
Notice: Finished catalog run in 1.61 seconds
[root@Legion100 /tmp/puppet]# 

Linux自动化运维之puppet的类和模块

[root@Legion100 /tmp/puppet]# service mysqld stop
停止 mysqld:                                              [确定]
[root@Legion100 /tmp/puppet]# service httpd stop
停止 httpd:                                               [确定]
[root@Legion100 /tmp/puppet]# cat class.pp
class test {
        $webserver = $operatingsystem ? {
                /(?i-mx:ubuntu|debian)/ => 'apache2',
                /(?i-mx:centos|redhat)/ => 'httpd',
        }

        package {["$webserver","php","mysql-server"]:
                ensure  => present,
        }

        service {['mysqld',httpd]:
                ensure  => true,
                enable  => true,
        }
}

#include test
class {'test':
}
[root@Legion100 /tmp/puppet]# puppet apply class.pp 2>/dev/null
Notice: Compiled catalog for legion100.dwhd.org in environment production in 0.36 seconds
Notice: /Stage[main]/Test/Service[httpd]/ensure: ensure changed 'stopped' to 'running'
Notice: /Stage[main]/Test/Service[mysqld]/ensure: ensure changed 'stopped' to 'running'
Notice: Finished catalog run in 1.59 seconds
[root@Legion100 /tmp/puppet]# service mysqld status
mysqld (pid  64796) 正在运行...
[root@Legion100 /tmp/puppet]# service httpd status
httpd (pid  64613) 正在运行...
[root@Legion100 /tmp/puppet]# 

Linux自动化运维之puppet的类和模块

[root@Legion100 /tmp/puppet]# id Legion
id: Legion:无此用户
[root@Legion100 /tmp/puppet]# cat class2.pp
class createuser ($grpname=testgrp,$username=testuser) {
        group {"$grpname":
                ensure  => present,
        }

        user{"$username":
                ensure  => present,
                gid             => $grpname,
        }
}

class {'createuser':
        grpname         => Legion,
        username        => Legion,
}
[root@Legion100 /tmp/puppet]# puppet apply class2.pp 2>/dev/null
Notice: Compiled catalog for legion100.dwhd.org in environment production in 0.17 seconds
Notice: /Stage[main]/Createuser/Group[Legion]/ensure: created
Notice: /Stage[main]/Createuser/User[Legion]/ensure: created
Notice: Finished catalog run in 0.98 seconds
[root@Legion100 /tmp/puppet]# id Legion
uid=2001(Legion) gid=2001(Legion) 组=2001(Legion)
[root@Legion100 /tmp/puppet]# 

Linux自动化运维之puppet的类和模块

[root@Legion100 /tmp/puppet]# rpm -e nginx
warning: /etc/nginx/nginx.conf saved as /etc/nginx/nginx.conf.rpmsave
[root@Legion100 /tmp/puppet]# service httpd start && service httpd stop
正在启动 httpd:                                           [确定]
停止 httpd:                                               [确定]
[root@Legion100 /tmp/puppet]# cat class3.pp
class nginx {
        package {'nginx':
                ensure => present,
        }

        file {'/etc/nginx/nginx.conf':
                ensure  => file,
                source  => '/configfile/nginx/nginx.conf',
        }
}

class nginx::web inherits nginx {
        service {'nginx':
                ensure  => true,
                path    => '/etc/rc.d/init.d/nginx',
                enable  => true,
        }
}

include nginx::web

[root@Legion100 /tmp/puppet]# puppet apply class3.pp 2>/dev/null
Notice: Compiled catalog for legion100.dwhd.org in environment production in 0.39 seconds
Notice: /Stage[main]/Nginx/File[/etc/nginx/nginx.conf]/ensure: defined content as '{md5}95f45f10386878664af2b7ccd1536ea4'
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: created
Notice: Finished catalog run in 4.45 seconds
[root@Legion100 /tmp/puppet]# 
[root@Legion100 /tmp/puppet]# puppet apply class3.pp -d -v
Debug: Runtime environment: puppet_version=3.7.1, run_mode=user, ruby_version=1.8.7
Debug: Executing '/bin/rpm --version'
Debug: Executing '/bin/rpm --version'
Debug: Executing '/bin/rpm -ql rpm'
Notice: Compiled catalog for legion100.dwhd.org in environment production in 0.42 seconds
Debug: Puppet::Type::Package::ProviderPacman: file /usr/bin/pacman does not exist
Debug: Puppet::Type::Package::ProviderZypper: file /usr/bin/zypper does not exist
Debug: Puppet::Type::Package::ProviderPkgin: file pkgin does not exist
Debug: Puppet::Type::Package::ProviderPorts: file /usr/local/sbin/portversion does not exist
Debug: Puppet::Type::Package::ProviderApt: file /usr/bin/apt-get does not exist
Debug: Puppet::Type::Package::ProviderNim: file /usr/sbin/nimclient does not exist
Debug: Puppet::Type::Package::ProviderOpenbsd: file pkg_info does not exist
Debug: Puppet::Type::Package::ProviderDpkg: file /usr/bin/dpkg does not exist
Debug: Puppet::Type::Package::ProviderAptitude: file /usr/bin/aptitude does not exist
Debug: Puppet::Type::Package::ProviderPkg: file /usr/bin/pkg does not exist
Debug: Puppet::Type::Package::ProviderUp2date: file /usr/sbin/up2date-nox does not exist
Debug: Puppet::Type::Package::ProviderAix: file /usr/sbin/installp does not exist
Debug: Puppet::Type::Package::ProviderSunfreeware: file pkg-get does not exist
Debug: Puppet::Type::Package::ProviderSun: file /usr/bin/pkginfo does not exist
Debug: Puppet::Type::Package::ProviderRug: file /usr/bin/rug does not exist
Debug: Puppet::Type::Package::ProviderFreebsd: file /usr/sbin/pkg_info does not exist
Debug: Puppet::Type::Package::ProviderAptrpm: file apt-get does not exist
Debug: Puppet::Type::Package::ProviderUrpmi: file urpmq does not exist
Debug: Puppet::Type::Package::ProviderPortage: file /usr/bin/emerge does not exist
Debug: Puppet::Type::Package::ProviderOpkg: file opkg does not exist
Debug: Puppet::Type::Package::ProviderFink: file /sw/bin/fink does not exist
Debug: Puppet::Type::Package::ProviderPortupgrade: file /usr/local/sbin/portinstall does not exist
Debug: Puppet::Type::Package::ProviderHpux: file /usr/sbin/swinstall does not exist
Warning: 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/lib/ruby/site_ruby/1.8/puppet/type/package.rb:430:in `default')
Debug: Puppet::Type::Service::ProviderDebian: file /usr/sbin/update-rc.d does not exist
Debug: Puppet::Type::Service::ProviderOpenrc: file /bin/rc-status does not exist
Debug: Puppet::Type::Service::ProviderRunit: file /usr/bin/sv does not exist
Debug: Puppet::Type::Service::ProviderGentoo: file /sbin/rc-update does not exist
Debug: Puppet::Type::Service::ProviderDaemontools: file /usr/bin/svc does not exist
Debug: Puppet::Type::Service::ProviderLaunchd: file /bin/launchctl does not exist
Debug: Puppet::Type::Service::ProviderSystemd: file systemctl does not exist
Debug: Creating default schedules
Debug: Using settings: adding file resource 'confdir': 'File[/etc/puppet]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/etc/puppet"}'
Debug: Puppet::Type::User::ProviderDirectoryservice: file /usr/bin/dsimport does not exist
Debug: Puppet::Type::User::ProviderPw: file pw does not exist
Debug: Failed to load library 'ldap' for feature 'ldap'
Debug: Puppet::Type::User::ProviderLdap: feature ldap is missing
Debug: Puppet::Type::User::ProviderUser_role_add: file roledel does not exist
Debug: Puppet::Type::Group::ProviderDirectoryservice: file /usr/bin/dscl does not exist
Debug: Puppet::Type::Group::ProviderPw: file pw does not exist
Debug: Failed to load library 'ldap' for feature 'ldap'
Debug: Puppet::Type::Group::ProviderLdap: feature ldap is missing
Debug: Using settings: adding file resource 'requestdir': 'File[/var/lib/puppet/ssl/certificate_requests]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/lib/puppet/ssl/certificate_requests"}'
Debug: Using settings: adding file resource 'statedir': 'File[/var/lib/puppet/state]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"1755", :backup=>false, :path=>"/var/lib/puppet/state"}'
Debug: Using settings: adding file resource 'privatedir': 'File[/var/lib/puppet/ssl/private]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/ssl/private"}'
Debug: Using settings: adding file resource 'rundir': 'File[/var/run/puppet]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/run/puppet"}'
Debug: Using settings: adding file resource 'certdir': 'File[/var/lib/puppet/ssl/certs]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/lib/puppet/ssl/certs"}'
Debug: Using settings: adding file resource 'clientyamldir': 'File[/var/lib/puppet/client_yaml]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/client_yaml"}'
Debug: Using settings: adding file resource 'logdir': 'File[/var/log/puppet]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/log/puppet"}'
Debug: Using settings: adding file resource 'publickeydir': 'File[/var/lib/puppet/ssl/public_keys]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/lib/puppet/ssl/public_keys"}'
Debug: Using settings: adding file resource 'libdir': 'File[/var/lib/puppet/lib]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/var/lib/puppet/lib"}'
Debug: Using settings: adding file resource 'lastrunreport': 'File[/var/lib/puppet/state/last_run_report.yaml]{:loglevel=>:debug, :ensure=>:file, :links=>:follow, :mode=>"640", :backup=>false, :path=>"/var/lib/puppet/state/last_run_report.yaml"}'
Debug: Using settings: adding file resource 'clientbucketdir': 'File[/var/lib/puppet/clientbucket]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/clientbucket"}'
Debug: Using settings: adding file resource 'vardir': 'File[/var/lib/puppet]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :backup=>false, :path=>"/var/lib/puppet"}'
Debug: Using settings: adding file resource 'privatekeydir': 'File[/var/lib/puppet/ssl/private_keys]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/ssl/private_keys"}'
Debug: Using settings: adding file resource 'pluginfactdest': 'File[/var/lib/puppet/facts.d]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/var/lib/puppet/facts.d"}'
Debug: Using settings: adding file resource 'graphdir': 'File[/var/lib/puppet/state/graphs]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/var/lib/puppet/state/graphs"}'
Debug: Using settings: adding file resource 'statefile': 'File[/var/lib/puppet/state/state.yaml]{:loglevel=>:debug, :ensure=>:file, :links=>:follow, :mode=>"660", :backup=>false, :path=>"/var/lib/puppet/state/state.yaml"}'
Debug: Using settings: adding file resource 'ssldir': 'File[/var/lib/puppet/ssl]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"771", :backup=>false, :path=>"/var/lib/puppet/ssl"}'
Debug: Using settings: adding file resource 'client_datadir': 'File[/var/lib/puppet/client_data]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/client_data"}'
Debug: Using settings: adding file resource 'lastrunfile': 'File[/var/lib/puppet/state/last_run_summary.yaml]{:loglevel=>:debug, :ensure=>:file, :links=>:follow, :mode=>"644", :backup=>false, :path=>"/var/lib/puppet/state/last_run_summary.yaml"}'
Debug: /File[/var/lib/puppet/state/graphs]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/clientbucket]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/state/last_run_report.yaml]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/ssl/certs]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/lib]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/ssl/private]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/state]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/state/last_run_summary.yaml]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/facts.d]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/client_data]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/state/state.yaml]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/ssl/certificate_requests]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/ssl]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/ssl/public_keys]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/client_yaml]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/ssl/private_keys]: Autorequiring File[/var/lib/puppet/ssl]
Debug: Finishing transaction 70083266769040
Debug: Loaded state in 0.00 seconds
Debug: Loaded state in 0.00 seconds
Info: Applying configuration version '1433868671'
Debug: Executing '/sbin/service nginx status'
Debug: Executing '/sbin/chkconfig nginx'
Debug: Executing '/sbin/service nginx start'
Debug: Executing '/sbin/chkconfig nginx'
Debug: Executing '/sbin/chkconfig nginx on'
Notice: /Stage[main]/Nginx::Web/Service[nginx]/ensure: ensure changed 'stopped' to 'running'
Debug: /Stage[main]/Nginx::Web/Service[nginx]: The container Class[Nginx::Web] will propagate my refresh event
Info: /Stage[main]/Nginx::Web/Service[nginx]: Unscheduling refresh on Service[nginx]
Debug: Class[Nginx::Web]: The container Stage[main] will propagate my refresh event
Debug: Prefetching yum resources for package
Debug: Executing '/bin/rpm --version'
Debug: Executing '/bin/rpm -qa --nosignature --nodigest --qf '%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n''
Debug: Finishing transaction 70083267136000
Debug: Storing state
Debug: Stored state in 0.04 seconds
Notice: Finished catalog run in 0.43 seconds
Debug: Using settings: adding file resource 'rrddir': 'File[/var/lib/puppet/rrd]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/rrd"}'
Debug: Finishing transaction 70083266310280
Debug: Received report to process from legion100.dwhd.org
Debug: Processing report from legion100.dwhd.org with processor Puppet::Reports::Store
[root@Legion100 /tmp/puppet]# 

Linux自动化运维之puppet的类和模块

 

Linux自动化运维之puppet的类和模块

 

Linux自动化运维之puppet的类和模块


二、puppet的模块

到目前位置,我所做的资源申报不、定义类、声明类等所有的功能都只能在一个manifest文件中实现,但这却非是最有效的基于puppet管理IT基础架构的方式

实践中,我们一般需要把manifest文件分解成易于理解的结构,例如将类文件、配置文件甚至包括后面将提到的模块文件等分类存放,并且通过某种机制在必要时将它们整合起来

这种机制就叫做"模块",它有助于以结构化,层次化的方式使用puppet,而puppet则基于"模块自动装载器"完成模块装载

从另一个角度来说,模块实际上就是一个按约定的、预定义的结构存放了很多个文件或子目录的目录,目录里的这些文件或子目录必须遵循其命名规范

puppet惠安次种规范在特定位置查找所需的模块文件,不过这些特定目录也可以通过puppet的配置参数modulepath定义

Linux自动化运维之puppet的类和模块

[root@Legion100 /tmp/puppet]# mkdir -pv /puppet/modules/nginx/{manifests,files,template}
mkdir: 已创建目录 "/puppet"
mkdir: 已创建目录 "/puppet/modules"
mkdir: 已创建目录 "/puppet/modules/nginx"
mkdir: 已创建目录 "/puppet/modules/nginx/manifests"
mkdir: 已创建目录 "/puppet/modules/nginx/files"
mkdir: 已创建目录 "/puppet/modules/nginx/template"
[root@Legion100 /tmp/puppet]# cd /puppet/modules/nginx/manifests/
[root@Legion100 /puppet/modules/nginx/manifests]# cat init.pp
class nginx {
        package {'nginx':
                ensure  => installed,
        }

        file {'nginx.conf':
                ensure  => file,
                source  => 'puppet:///modules/nginx/nginx.conf',
                mode    => 750,
                require => Package['nginx'],
                path    => '/etc/nginx/nginx.conf',
        }

        service {'nginx':
                ensure          => true,
                enable          => true,
                require         => Package['nginx'],
                subscribe       => File['nginx.conf'],
        }
}


[root@Legion100 /puppet/modules/nginx/manifests]# cp /etc/nginx/nginx.conf ../files/
[root@Legion100 /puppet/modules/nginx/manifests]# sed -ri 's/(worker_processes).*/\1    4;/' ../files/nginx.conf
[root@Legion100 /puppet/modules/nginx/manifests]# sed -ri 's/(worker_connections).*/\1    10240;/' ../files/nginx.conf
[root@Legion100 /puppet/modules/nginx/manifests]# grep -E 'worker_processes|worker_connections' ../files/nginx.conf
worker_processes    4;
    worker_connections    10240;
[root@Legion100 /puppet/modules/nginx/manifests]# service nginx stop
停止 nginx:                                               [确定]
[root@Legion100 /puppet/modules/nginx/manifests]# rpm -e nginx
warning: /etc/nginx/nginx.conf saved as /etc/nginx/nginx.conf.rpmsave
[root@Legion100 /puppet/modules/nginx/manifests]# puppet apply --modulepath=/puppet/modules/ -d -v -e 'include nginx'
Debug: Runtime environment: ruby_version=1.8.7, run_mode=user, puppet_version=3.7.1
Debug: importing '/puppet/modules/nginx/manifests/init.pp' in environment production
Debug: Automatically imported nginx from nginx into production
Debug: Executing '/bin/rpm --version'
Debug: Executing '/bin/rpm --version'
Debug: Executing '/bin/rpm -ql rpm'
Notice: Compiled catalog for legion100.dwhd.org in environment production in 0.41 seconds
Debug: Puppet::Type::Package::ProviderAptrpm: file apt-get does not exist
Debug: Puppet::Type::Package::ProviderUrpmi: file urpmi does not exist
Debug: Puppet::Type::Package::ProviderPortage: file /usr/bin/emerge does not exist
Debug: Puppet::Type::Package::ProviderOpkg: file opkg does not exist
Debug: Puppet::Type::Package::ProviderFink: file /sw/bin/fink does not exist
Debug: Puppet::Type::Package::ProviderPortupgrade: file /usr/local/sbin/portupgrade does not exist
Debug: Puppet::Type::Package::ProviderHpux: file /usr/sbin/swinstall does not exist
Debug: Puppet::Type::Package::ProviderPacman: file /usr/bin/pacman does not exist
Debug: Puppet::Type::Package::ProviderZypper: file /usr/bin/zypper does not exist
Debug: Puppet::Type::Package::ProviderPkgin: file pkgin does not exist
Debug: Puppet::Type::Package::ProviderPorts: file /usr/local/sbin/portupgrade does not exist
Debug: Puppet::Type::Package::ProviderApt: file /usr/bin/apt-get does not exist
Debug: Puppet::Type::Package::ProviderNim: file /usr/sbin/nimclient does not exist
Debug: Puppet::Type::Package::ProviderPkg: file /usr/bin/pkg does not exist
Debug: Puppet::Type::Package::ProviderOpenbsd: file pkg_info does not exist
Debug: Puppet::Type::Package::ProviderDpkg: file /usr/bin/dpkg does not exist
Debug: Puppet::Type::Package::ProviderAptitude: file /usr/bin/aptitude does not exist
Debug: Puppet::Type::Package::ProviderUp2date: file /usr/sbin/up2date-nox does not exist
Debug: Puppet::Type::Package::ProviderAix: file /usr/sbin/installp does not exist
Debug: Puppet::Type::Package::ProviderSunfreeware: file pkg-get does not exist
Debug: Puppet::Type::Package::ProviderSun: file /usr/bin/pkginfo does not exist
Debug: Puppet::Type::Package::ProviderRug: file /usr/bin/rug does not exist
Debug: Puppet::Type::Package::ProviderFreebsd: file /usr/sbin/pkg_info does not exist
Warning: 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/lib/ruby/site_ruby/1.8/puppet/type/package.rb:430:in `default')
Debug: Puppet::Type::Service::ProviderSystemd: file systemctl does not exist
Debug: Puppet::Type::Service::ProviderDebian: file /usr/sbin/update-rc.d does not exist
Debug: Puppet::Type::Service::ProviderOpenrc: file /bin/rc-status does not exist
Debug: Puppet::Type::Service::ProviderRunit: file /usr/bin/sv does not exist
Debug: Puppet::Type::Service::ProviderGentoo: file /sbin/rc-update does not exist
Debug: Puppet::Type::Service::ProviderDaemontools: file /usr/bin/svc does not exist
Debug: Puppet::Type::Service::ProviderLaunchd: file /bin/launchctl does not exist
Debug: Creating default schedules
Debug: Using settings: adding file resource 'confdir': 'File[/etc/puppet]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/etc/puppet"}'
Debug: Puppet::Type::User::ProviderPw: file pw does not exist
Debug: Puppet::Type::User::ProviderDirectoryservice: file /usr/bin/dsimport does not exist
Debug: Failed to load library 'ldap' for feature 'ldap'
Debug: Puppet::Type::User::ProviderLdap: feature ldap is missing
Debug: Puppet::Type::User::ProviderUser_role_add: file roleadd does not exist
Debug: Puppet::Type::Group::ProviderPw: file pw does not exist
Debug: Puppet::Type::Group::ProviderDirectoryservice: file /usr/bin/dscl does not exist
Debug: Failed to load library 'ldap' for feature 'ldap'
Debug: Puppet::Type::Group::ProviderLdap: feature ldap is missing
Debug: Using settings: adding file resource 'requestdir': 'File[/var/lib/puppet/ssl/certificate_requests]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/lib/puppet/ssl/certificate_requests"}'
Debug: Using settings: adding file resource 'statedir': 'File[/var/lib/puppet/state]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"1755", :backup=>false, :path=>"/var/lib/puppet/state"}'
Debug: Using settings: adding file resource 'privatedir': 'File[/var/lib/puppet/ssl/private]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/ssl/private"}'
Debug: Using settings: adding file resource 'rundir': 'File[/var/run/puppet]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/run/puppet"}'
Debug: Using settings: adding file resource 'certdir': 'File[/var/lib/puppet/ssl/certs]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/lib/puppet/ssl/certs"}'
Debug: Using settings: adding file resource 'clientyamldir': 'File[/var/lib/puppet/client_yaml]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/client_yaml"}'
Debug: Using settings: adding file resource 'logdir': 'File[/var/log/puppet]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/log/puppet"}'
Debug: Using settings: adding file resource 'publickeydir': 'File[/var/lib/puppet/ssl/public_keys]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/lib/puppet/ssl/public_keys"}'
Debug: Using settings: adding file resource 'libdir': 'File[/var/lib/puppet/lib]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/var/lib/puppet/lib"}'
Debug: Using settings: adding file resource 'lastrunreport': 'File[/var/lib/puppet/state/last_run_report.yaml]{:loglevel=>:debug, :ensure=>:file, :links=>:follow, :mode=>"640", :backup=>false, :path=>"/var/lib/puppet/state/last_run_report.yaml"}'
Debug: Using settings: adding file resource 'clientbucketdir': 'File[/var/lib/puppet/clientbucket]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/clientbucket"}'
Debug: Using settings: adding file resource 'vardir': 'File[/var/lib/puppet]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :backup=>false, :path=>"/var/lib/puppet"}'
Debug: Using settings: adding file resource 'privatekeydir': 'File[/var/lib/puppet/ssl/private_keys]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/ssl/private_keys"}'
Debug: Using settings: adding file resource 'pluginfactdest': 'File[/var/lib/puppet/facts.d]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/var/lib/puppet/facts.d"}'
Debug: Using settings: adding file resource 'graphdir': 'File[/var/lib/puppet/state/graphs]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/var/lib/puppet/state/graphs"}'
Debug: Using settings: adding file resource 'statefile': 'File[/var/lib/puppet/state/state.yaml]{:loglevel=>:debug, :ensure=>:file, :links=>:follow, :mode=>"660", :backup=>false, :path=>"/var/lib/puppet/state/state.yaml"}'
Debug: Using settings: adding file resource 'ssldir': 'File[/var/lib/puppet/ssl]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"771", :backup=>false, :path=>"/var/lib/puppet/ssl"}'
Debug: Using settings: adding file resource 'client_datadir': 'File[/var/lib/puppet/client_data]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/client_data"}'
Debug: Using settings: adding file resource 'lastrunfile': 'File[/var/lib/puppet/state/last_run_summary.yaml]{:loglevel=>:debug, :ensure=>:file, :links=>:follow, :mode=>"644", :backup=>false, :path=>"/var/lib/puppet/state/last_run_summary.yaml"}'
Debug: /File[/var/lib/puppet/ssl]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/facts.d]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/client_yaml]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/state/graphs]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/clientbucket]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/ssl/public_keys]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/lib]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/ssl/certificate_requests]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/state/state.yaml]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/client_data]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/state]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/state/last_run_report.yaml]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/state/last_run_summary.yaml]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/ssl/certs]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/ssl/private_keys]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/ssl/private]: Autorequiring File[/var/lib/puppet/ssl]
Debug: Finishing transaction 70190440130660
Debug: Loaded state in 0.00 seconds
Debug: Loaded state in 0.00 seconds
Debug: /Stage[main]/Nginx/Service[nginx]/require: requires Package[nginx]
Debug: /Stage[main]/Nginx/Service[nginx]/subscribe: subscribes to File[nginx.conf]
Debug: /Stage[main]/Nginx/File[nginx.conf]/require: requires Package[nginx]
Info: Applying configuration version '1433876215'
Debug: Prefetching yum resources for package
Debug: Executing '/bin/rpm --version'
Debug: Executing '/bin/rpm -qa --nosignature --nodigest --qf '%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n''
Debug: Executing '/bin/rpm -q nginx --nosignature --nodigest --qf %{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n'
Debug: Executing '/usr/bin/yum -d 0 -e 0 -y list nginx'
Debug: Package[nginx](provider=yum): Ensuring => present
Debug: Executing '/usr/bin/yum -d 0 -e 0 -y install nginx'
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: created
Debug: /Stage[main]/Nginx/Package[nginx]: The container Class[Nginx] will propagate my refresh event
Info: Computing checksum on file /etc/nginx/nginx.conf
Info: FileBucket got a duplicate file {md5}d9dfc198c249bb4ac341198a752b9458
Info: /Stage[main]/Nginx/File[nginx.conf]: Filebucketed /etc/nginx/nginx.conf to puppet with sum d9dfc198c249bb4ac341198a752b9458
Notice: /Stage[main]/Nginx/File[nginx.conf]/content: content changed '{md5}d9dfc198c249bb4ac341198a752b9458' to '{md5}bcebff7eac6e3e24b208200a3827928b'
Notice: /Stage[main]/Nginx/File[nginx.conf]/mode: mode changed '0644' to '0750'
Debug: /Stage[main]/Nginx/File[nginx.conf]: The container Class[Nginx] will propagate my refresh event
Info: /Stage[main]/Nginx/File[nginx.conf]: Scheduling refresh of Service[nginx]
Debug: /Stage[main]/Nginx/File[nginx.conf]: The container Class[Nginx] will propagate my refresh event
Info: /Stage[main]/Nginx/File[nginx.conf]: Scheduling refresh of Service[nginx]
Debug: Executing '/sbin/service nginx status'
Debug: Executing '/sbin/chkconfig nginx'
Debug: Executing '/sbin/service nginx start'
Debug: Executing '/sbin/chkconfig nginx'
Debug: Executing '/sbin/chkconfig nginx on'
Notice: /Stage[main]/Nginx/Service[nginx]/ensure: ensure changed 'stopped' to 'running'
Debug: /Stage[main]/Nginx/Service[nginx]: The container Class[Nginx] will propagate my refresh event
Info: /Stage[main]/Nginx/Service[nginx]: Unscheduling refresh on Service[nginx]
Debug: Class[Nginx]: The container Stage[main] will propagate my refresh event
Debug: Finishing transaction 70190440844080
Debug: Storing state
Debug: Stored state in 0.01 seconds
Notice: Finished catalog run in 5.64 seconds
Debug: Using settings: adding file resource 'rrddir': 'File[/var/lib/puppet/rrd]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/rrd"}'
Debug: Finishing transaction 70190439623240
Debug: Received report to process from legion100.dwhd.org
Debug: Processing report from legion100.dwhd.org with processor Puppet::Reports::Store
[root@Legion100 /puppet/modules/nginx/manifests]# 

Linux自动化运维之puppet的类和模块

[root@Legion100 /puppet/modules/nginx/manifests]# cp -r /puppet/modules/nginx/ /etc/puppet/modules/
[root@Legion100 /puppet/modules/nginx/manifests]# cd
[root@Legion100 ~]# service nginx stop
停止 nginx:                                               [确定]
[root@Legion100 ~]# rpm -e nginx
warning: /etc/nginx/nginx.conf saved as /etc/nginx/nginx.conf.rpmsave
[root@Legion100 ~]# puppet apply -d -v -e 'include nginx'
Debug: Runtime environment: run_mode=user, ruby_version=1.8.7, puppet_version=3.7.1
Debug: importing '/etc/puppet/modules/nginx/manifests/init.pp' in environment production
Debug: Automatically imported nginx from nginx into production
Debug: Executing '/bin/rpm --version'
Debug: Executing '/bin/rpm --version'
Debug: Executing '/bin/rpm -ql rpm'
Notice: Compiled catalog for legion100.dwhd.org in environment production in 0.41 seconds
Debug: Puppet::Type::Package::ProviderPacman: file /usr/bin/pacman does not exist
Debug: Puppet::Type::Package::ProviderZypper: file /usr/bin/zypper does not exist
Debug: Puppet::Type::Package::ProviderPkgin: file pkgin does not exist
Debug: Puppet::Type::Package::ProviderPorts: file /usr/local/sbin/portversion does not exist
Debug: Puppet::Type::Package::ProviderApt: file /usr/bin/apt-get does not exist
Debug: Puppet::Type::Package::ProviderNim: file /usr/sbin/nimclient does not exist
Debug: Puppet::Type::Package::ProviderOpenbsd: file pkg_info does not exist
Debug: Puppet::Type::Package::ProviderDpkg: file /usr/bin/dpkg does not exist
Debug: Puppet::Type::Package::ProviderAptitude: file /usr/bin/aptitude does not exist
Debug: Puppet::Type::Package::ProviderPkg: file /usr/bin/pkg does not exist
Debug: Puppet::Type::Package::ProviderUp2date: file /usr/sbin/up2date-nox does not exist
Debug: Puppet::Type::Package::ProviderAix: file /usr/sbin/installp does not exist
Debug: Puppet::Type::Package::ProviderSunfreeware: file pkg-get does not exist
Debug: Puppet::Type::Package::ProviderSun: file /usr/bin/pkginfo does not exist
Debug: Puppet::Type::Package::ProviderRug: file /usr/bin/rug does not exist
Debug: Puppet::Type::Package::ProviderFreebsd: file /usr/sbin/pkg_info does not exist
Debug: Puppet::Type::Package::ProviderAptrpm: file apt-get does not exist
Debug: Puppet::Type::Package::ProviderUrpmi: file urpmq does not exist
Debug: Puppet::Type::Package::ProviderPortage: file /usr/bin/emerge does not exist
Debug: Puppet::Type::Package::ProviderOpkg: file opkg does not exist
Debug: Puppet::Type::Package::ProviderFink: file /sw/bin/fink does not exist
Debug: Puppet::Type::Package::ProviderPortupgrade: file /usr/local/sbin/portinstall does not exist
Debug: Puppet::Type::Package::ProviderHpux: file /usr/sbin/swinstall does not exist
Warning: 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/lib/ruby/site_ruby/1.8/puppet/type/package.rb:430:in `default')
Debug: Puppet::Type::Service::ProviderDebian: file /usr/sbin/update-rc.d does not exist
Debug: Puppet::Type::Service::ProviderOpenrc: file /bin/rc-status does not exist
Debug: Puppet::Type::Service::ProviderRunit: file /usr/bin/sv does not exist
Debug: Puppet::Type::Service::ProviderGentoo: file /sbin/rc-update does not exist
Debug: Puppet::Type::Service::ProviderDaemontools: file /usr/bin/svc does not exist
Debug: Puppet::Type::Service::ProviderLaunchd: file /bin/launchctl does not exist
Debug: Puppet::Type::Service::ProviderSystemd: file systemctl does not exist
Debug: Creating default schedules
Debug: Using settings: adding file resource 'confdir': 'File[/etc/puppet]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/etc/puppet"}'
Debug: Puppet::Type::User::ProviderDirectoryservice: file /usr/bin/dsimport does not exist
Debug: Puppet::Type::User::ProviderPw: file pw does not exist
Debug: Failed to load library 'ldap' for feature 'ldap'
Debug: Puppet::Type::User::ProviderLdap: feature ldap is missing
Debug: Puppet::Type::User::ProviderUser_role_add: file roledel does not exist
Debug: Puppet::Type::Group::ProviderDirectoryservice: file /usr/bin/dscl does not exist
Debug: Puppet::Type::Group::ProviderPw: file pw does not exist
Debug: Failed to load library 'ldap' for feature 'ldap'
Debug: Puppet::Type::Group::ProviderLdap: feature ldap is missing
Debug: Using settings: adding file resource 'requestdir': 'File[/var/lib/puppet/ssl/certificate_requests]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/lib/puppet/ssl/certificate_requests"}'
Debug: Using settings: adding file resource 'statedir': 'File[/var/lib/puppet/state]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"1755", :backup=>false, :path=>"/var/lib/puppet/state"}'
Debug: Using settings: adding file resource 'privatedir': 'File[/var/lib/puppet/ssl/private]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/ssl/private"}'
Debug: Using settings: adding file resource 'rundir': 'File[/var/run/puppet]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/run/puppet"}'
Debug: Using settings: adding file resource 'certdir': 'File[/var/lib/puppet/ssl/certs]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/lib/puppet/ssl/certs"}'
Debug: Using settings: adding file resource 'clientyamldir': 'File[/var/lib/puppet/client_yaml]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/client_yaml"}'
Debug: Using settings: adding file resource 'logdir': 'File[/var/log/puppet]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/log/puppet"}'
Debug: Using settings: adding file resource 'publickeydir': 'File[/var/lib/puppet/ssl/public_keys]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"755", :backup=>false, :path=>"/var/lib/puppet/ssl/public_keys"}'
Debug: Using settings: adding file resource 'libdir': 'File[/var/lib/puppet/lib]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/var/lib/puppet/lib"}'
Debug: Using settings: adding file resource 'lastrunreport': 'File[/var/lib/puppet/state/last_run_report.yaml]{:loglevel=>:debug, :ensure=>:file, :links=>:follow, :mode=>"640", :backup=>false, :path=>"/var/lib/puppet/state/last_run_report.yaml"}'
Debug: Using settings: adding file resource 'clientbucketdir': 'File[/var/lib/puppet/clientbucket]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/clientbucket"}'
Debug: Using settings: adding file resource 'vardir': 'File[/var/lib/puppet]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :backup=>false, :path=>"/var/lib/puppet"}'
Debug: Using settings: adding file resource 'privatekeydir': 'File[/var/lib/puppet/ssl/private_keys]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/ssl/private_keys"}'
Debug: Using settings: adding file resource 'pluginfactdest': 'File[/var/lib/puppet/facts.d]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/var/lib/puppet/facts.d"}'
Debug: Using settings: adding file resource 'graphdir': 'File[/var/lib/puppet/state/graphs]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :backup=>false, :path=>"/var/lib/puppet/state/graphs"}'
Debug: Using settings: adding file resource 'statefile': 'File[/var/lib/puppet/state/state.yaml]{:loglevel=>:debug, :ensure=>:file, :links=>:follow, :mode=>"660", :backup=>false, :path=>"/var/lib/puppet/state/state.yaml"}'
Debug: Using settings: adding file resource 'ssldir': 'File[/var/lib/puppet/ssl]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"771", :backup=>false, :path=>"/var/lib/puppet/ssl"}'
Debug: Using settings: adding file resource 'client_datadir': 'File[/var/lib/puppet/client_data]{:loglevel=>:debug, :ensure=>:directory, :links=>:follow, :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/client_data"}'
Debug: Using settings: adding file resource 'lastrunfile': 'File[/var/lib/puppet/state/last_run_summary.yaml]{:loglevel=>:debug, :ensure=>:file, :links=>:follow, :mode=>"644", :backup=>false, :path=>"/var/lib/puppet/state/last_run_summary.yaml"}'
Debug: /File[/var/lib/puppet/client_data]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/state/state.yaml]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/ssl/certificate_requests]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/ssl]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/ssl/public_keys]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/client_yaml]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/ssl/private_keys]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/state/graphs]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/clientbucket]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/state/last_run_report.yaml]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/ssl/certs]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/lib]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/ssl/private]: Autorequiring File[/var/lib/puppet/ssl]
Debug: /File[/var/lib/puppet/state]: Autorequiring File[/var/lib/puppet]
Debug: /File[/var/lib/puppet/state/last_run_summary.yaml]: Autorequiring File[/var/lib/puppet/state]
Debug: /File[/var/lib/puppet/facts.d]: Autorequiring File[/var/lib/puppet]
Debug: Finishing transaction 69991286813760
Debug: Loaded state in 0.00 seconds
Debug: Loaded state in 0.00 seconds
Debug: /Stage[main]/Nginx/File[nginx.conf]/require: requires Package[nginx]
Debug: /Stage[main]/Nginx/Service[nginx]/require: requires Package[nginx]
Debug: /Stage[main]/Nginx/Service[nginx]/subscribe: subscribes to File[nginx.conf]
Info: Applying configuration version '1433912497'
Debug: Prefetching yum resources for package
Debug: Executing '/bin/rpm --version'
Debug: Executing '/bin/rpm -qa --nosignature --nodigest --qf '%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n''
Debug: Executing '/bin/rpm -q nginx --nosignature --nodigest --qf %{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\n'
Debug: Executing '/usr/bin/yum -d 0 -e 0 -y list nginx'
Debug: Package[nginx](provider=yum): Ensuring => present
Debug: Executing '/usr/bin/yum -d 0 -e 0 -y install nginx'
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: created
Debug: /Stage[main]/Nginx/Package[nginx]: The container Class[Nginx] will propagate my refresh event
Info: Computing checksum on file /etc/nginx/nginx.conf
Info: FileBucket got a duplicate file {md5}d9dfc198c249bb4ac341198a752b9458
Info: /Stage[main]/Nginx/File[nginx.conf]: Filebucketed /etc/nginx/nginx.conf to puppet with sum d9dfc198c249bb4ac341198a752b9458
Notice: /Stage[main]/Nginx/File[nginx.conf]/content: content changed '{md5}d9dfc198c249bb4ac341198a752b9458' to '{md5}bcebff7eac6e3e24b208200a3827928b'
Notice: /Stage[main]/Nginx/File[nginx.conf]/mode: mode changed '0644' to '0750'
Debug: /Stage[main]/Nginx/File[nginx.conf]: The container Class[Nginx] will propagate my refresh event
Info: /Stage[main]/Nginx/File[nginx.conf]: Scheduling refresh of Service[nginx]
Debug: /Stage[main]/Nginx/File[nginx.conf]: The container Class[Nginx] will propagate my refresh event
Info: /Stage[main]/Nginx/File[nginx.conf]: Scheduling refresh of Service[nginx]
Debug: Executing '/sbin/service nginx status'
Debug: Executing '/sbin/chkconfig nginx'
Debug: Executing '/sbin/service nginx start'
Debug: Executing '/sbin/chkconfig nginx'
Debug: Executing '/sbin/chkconfig nginx on'
Notice: /Stage[main]/Nginx/Service[nginx]/ensure: ensure changed 'stopped' to 'running'
Debug: /Stage[main]/Nginx/Service[nginx]: The container Class[Nginx] will propagate my refresh event
Info: /Stage[main]/Nginx/Service[nginx]: Unscheduling refresh on Service[nginx]
Debug: Class[Nginx]: The container Stage[main] will propagate my refresh event
Debug: Finishing transaction 69991287496940
Debug: Storing state
Debug: Stored state in 0.01 seconds
Notice: Finished catalog run in 15.61 seconds
Debug: Using settings: adding file resource 'rrddir': 'File[/var/lib/puppet/rrd]{:group=>"puppet", :loglevel=>:debug, :ensure=>:directory, :links=>:follow, :owner=>"puppet", :mode=>"750", :backup=>false, :path=>"/var/lib/puppet/rrd"}'
Debug: Finishing transaction 69991286300500
Debug: Received report to process from legion100.dwhd.org
Debug: Processing report from legion100.dwhd.org with processor Puppet::Reports::Store
[root@Legion100 ~]# service nginx status
nginx (pid  74667) 正在运行...
[root@Legion100 ~]# ps aux | grep nginx
root      74667  0.0  0.1  96020  1960 ?        Ss   13:01   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx     74668  0.0  0.3 100036  6320 ?        S    13:01   0:00 nginx: worker process                   
nginx     74669  0.0  0.3 100036  6320 ?        S    13:01   0:00 nginx: worker process                   
nginx     74670  0.0  0.3 100036  6320 ?        S    13:01   0:00 nginx: worker process                   
nginx     74671  0.0  0.3 100036  6228 ?        S    13:01   0:00 nginx: worker process                   
root      74715  0.0  0.0 103256   856 pts/1    S+   13:02   0:00 grep --color=auto nginx
[root@Legion100 ~]# cat /etc/nginx/nginx.conf | grep 1024
    worker_connections    10240;
[root@Legion100 ~]# 

Linux自动化运维之puppet的类和模块

Linux自动化运维之puppet的类和模块

[root@Legion100 ~]# cd /etc/puppet/modules/
[root@Legion100 /etc/puppet/modules]# mkdir -pv mysql/{manifests,files,temlates}
mkdir: 已创建目录 "mysql"
mkdir: 已创建目录 "mysql/manifests"
mkdir: 已创建目录 "mysql/files"
mkdir: 已创建目录 "mysql/temlates"
[root@Legion100 /etc/puppet/modules]# cd mysql/manifests/
[root@Legion100 /etc/puppet/modules/mysql/manifests]# cat init.pp
class mysql {
        package {"mysql_server":
                ensure  => installed,
        }

        file {'my.cnf':
                ensure  => file,
                source  => 'puppet:///modules/mysql/my.cnf',
                path    => '/etc/my.cnf',
                require => Package['mysql_server'],
        }

        service {'mysqld':
                ensure  => true,
                enable  => true,
                require => Package['mysql_server'],
                subscribe       => File['my.cnf'],
        }
}
[root@Legion100 /etc/puppet/modules/mysql/manifests]# puppet parser validate init.pp  #校验是否有语法错误
[root@Legion100 /etc/puppet]# puppet apply -e 'include mysql'
Notice: Compiled catalog for legion100.dwhd.org in environment production in 0.40 seconds
Warning: 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/lib/ruby/site_ruby/1.8/puppet/type/package.rb:430:in `default')
Notice: /Stage[main]/Mysql/Package[mysql-server]/ensure: created
Notice: /Stage[main]/Mysql/File[my.cnf]/content: content changed '{md5}8ace886bbe7e274448bc8bea16d3ead6' to '{md5}3a2bb66fe343ea7cfc613ce29b3e74a3'
Notice: /Stage[main]/Mysql/Service[mysqld]/ensure: ensure changed 'stopped' to 'running'
Notice: Finished catalog run in 8.40 seconds
[root@Legion100 /etc/puppet]# service mysqld status
mysqld (pid  82488) 正在运行...
[root@Legion100 /etc/puppet]# tail -3 /etc/my.cnf 
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#test puppet
[root@Legion100 /etc/puppet]# 
[root@Legion100 ~]# cd /etc/puppet/modules/
[root@Legion100 /etc/puppet/modules]# mkdir -pv mysql/{manifests,files,temlates}
mkdir: 已创建目录 "mysql"
mkdir: 已创建目录 "mysql/manifests"
mkdir: 已创建目录 "mysql/files"
mkdir: 已创建目录 "mysql/temlates"
[root@Legion100 /etc/puppet/modules]# cd mysql/manifests/
[root@Legion100 /etc/puppet/modules/mysql/manifests]# cat init.pp
class mysql {
        package {"mysql_server":
                ensure  => installed,
        }

        file {'my.cnf':
                ensure  => file,
                source  => 'puppet:///modules/mysql/my.cnf',
                path    => '/etc/my.cnf',
                require => Package['mysql_server'],
        }

        service {'mysqld':
                ensure  => true,
                enable  => true,
                require => Package['mysql_server'],
                subscribe       => File['my.cnf'],
        }
}
[root@Legion100 /etc/puppet/modules/mysql/manifests]# puppet parser validate init.pp  #校验是否有语法错误
[root@Legion100 /etc/puppet]# puppet apply -e 'include mysql'
Notice: Compiled catalog for legion100.dwhd.org in environment production in 0.40 seconds
Warning: 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/lib/ruby/site_ruby/1.8/puppet/type/package.rb:430:in `default')
Notice: /Stage[main]/Mysql/Package[mysql-server]/ensure: created
Notice: /Stage[main]/Mysql/File[my.cnf]/content: content changed '{md5}8ace886bbe7e274448bc8bea16d3ead6' to '{md5}3a2bb66fe343ea7cfc613ce29b3e74a3'
Notice: /Stage[main]/Mysql/Service[mysqld]/ensure: ensure changed 'stopped' to 'running'
Notice: Finished catalog run in 8.40 seconds
[root@Legion100 /etc/puppet]# service mysqld status
mysqld (pid  82488) 正在运行...
[root@Legion100 /etc/puppet]# tail -3 /etc/my.cnf 
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#test puppet
[root@Legion100 /etc/puppet]# 

Linux自动化运维之puppet的类和模块
Linux自动化运维之puppet的类和模块

[root@Legion100 /tmp/puppet]# rpm -e nginx
warning: /etc/nginx/nginx.conf saved as /etc/nginx/nginx.conf.rpmsave
[root@Legion100 /tmp/puppet]# rpm -e mysql-server
warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave
[root@Legion100 /tmp/puppet]# cat site.pp
node 'Legion100.dwhd.org' {
        include nginx
        include mysql
}
#站点清单,使用node指明有多少个节点,每个节点是如果调用类的

[root@Legion100 /tmp/puppet]# puppet apply site.pp 2>/dev/null
Notice: Compiled catalog for legion100.dwhd.org in environment production in 0.41 seconds
Notice: /Stage[main]/Mysql/Package[mysql-server]/ensure: created
Notice: /Stage[main]/Mysql/Service[mysqld]/ensure: ensure changed 'stopped' to 'running'
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: created
Notice: /Stage[main]/Nginx/File[nginx.conf]/content: content changed '{md5}d9dfc198c249bb4ac341198a752b9458' to '{md5}bcebff7eac6e3e24b208200a3827928b'
Notice: /Stage[main]/Nginx/File[nginx.conf]/mode: mode changed '0644' to '0750'
Notice: /Stage[main]/Nginx/Service[nginx]/ensure: ensure changed 'stopped' to 'running'
Notice: Finished catalog run in 11.24 seconds
[root@Legion100 /tmp/puppet]# 

Linux自动化运维之puppet的类和模块

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

lookback

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: