|
puppet apply是Puppet的运行命令,主要在检测manifests时或在没有网络连接的情况下使用。不同于puppet agent,puppet apply在运行时不会连接Master
命令:puppet apply #运行本地manifests
-h|--help #查看帮助
-V|--version #显示版本信息
-d|--debug #启用完整的调试模式
-v|--verbose #显示详细信息
-e|--execute #执行命令中指定的puppet代码
--detailed-exitcodes #提供详细的退出代码
-l|--logdest <file> #日志发送方式,默认采用syslog配置
--catalog <catalog> #运行puppet master采用--compile输出JSON代码
[iyunv@linux57poc ~]# puppet help apply
puppet-apply(8) -- Apply Puppet manifests locally
========
SYNOPSIS
--------
Applies a standalone Puppet manifest to the local system.
USAGE
-----
puppet apply [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose]
[-e|--execute] [--detailed-exitcodes] [-l|--logdest <file>]
[--apply <catalog>] [--catalog <catalog>] <file>
DESCRIPTION
-----------
This is the standalone puppet execution tool; use it to apply
individual manifests.
When provided with a modulepath, via command line or config file, puppet
apply can effectively mimic the catalog that would be served by puppet
master with access to the same modules, although there are some subtle
differences. When combined with scheduling and an automated system for
pushing manifests, this can be used to implement a serverless Puppet
site.
Most users should use 'puppet agent' and 'puppet master' for site-wide
manifests.
OPTIONS
-------
Note that any configuration parameter that's valid in the configuration
file is also a valid long argument. For example, 'modulepath' is a
valid configuration parameter, so you can specify '--tags <class>,<tag>'
as an argument.
See the configuration file documentation at
http://docs.puppetlabs.com/references/stable/configuration.html for the
full list of acceptable parameters. A commented list of all
configuration options can also be generated by running puppet with
'--genconfig'.
* --debug:
Enable full debugging.
* --detailed-exitcodes:
Provide transaction information via exit codes. If this is enabled, an exit
code of '2' means there were changes, an exit code of '4' means there were
failures during the transaction, and an exit code of '6' means there were both
changes and failures.
* --help:
Print this help message
* --loadclasses:
Load any stored classes. 'puppet agent' caches configured classes
(usually at /etc/puppet/classes.txt), and setting this option causes
all of those classes to be set in your puppet manifest.
* --logdest:
Where to send messages. Choose between syslog, the console, and a log
file. Defaults to sending messages to the console.
* --execute:
Execute a specific piece of Puppet code
* --verbose:
Print extra information.
* --apply:
Apply a JSON catalog (such as one generated with 'puppet master --compile'). You can
either specify a JSON file or pipe in JSON from standard input. Deprecated, please
use --catalog instead.
* --catalog:
Apply a JSON catalog (such as one generated with 'puppet master --compile'). You can
either specify a JSON file or pipe in JSON from standard input.
EXAMPLE
-------
$ puppet apply -l /tmp/manifest.log manifest.pp
$ puppet apply --modulepath=/root/dev/modules -e "include ntpd::server"
$ puppet apply --catalog catalog.json
AUTHOR
------
Luke Kanies
COPYRIGHT
---------
Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
举例说明:
以下为写好的puppet模块,目的是通过erb模板创建/etc/motd文件
[iyunv@linux58poc puppet]# mkdir -p /etc/puppet/modules/motd/manifests
[iyunv@linux58poc puppet]# mkdir -p /etc/puppet/modules/motd/templates
[iyunv@linux58poc puppet]# mkdir -p /etc/puppet/modules/motd/files
[iyunv@linux58poc puppet]# vim /etc/puppet/modules/motd/manifests/init.pp
class motd{
package{ setup:
ensure => present,
}
file{ "/etc/motd":
owner => "root",
group => "root",
mode => 0400,
content => template("motd/motd.erb"),
require => Package["setup"],
}
}
[iyunv@linux58poc puppet]# vim /etc/puppet/modules/motd/templates/motd.erb
------------a few of facter values-------------
myhostname = <%= hostname%>
eth0_ip = <%= ipaddress_eth0%>
kernel = <%= kernelrelease%>
system release = <%= lsbdistdescription%>
puppetversion = <%= puppetversion%>
rubyversion = <%= rubyversion%>
....................
....
------------------------------------------------
[iyunv@linux58poc puppet]#
eg.将输出信息输出到日志文件中
[iyunv@linux58poc ~]# cat /tmp/motd.log
Thu Jan 09 05:32:37 +0800 2014 Puppet (notice): Finished catalog run in 0.04 seconds
[iyunv@linux58poc ~]# puppet apply --debug -l /tmp/motd.log /etc/puppet/modules/motd/manifests/init.pp
[iyunv@linux58poc ~]# cat /tmp/motd.log
Thu Jan 09 05:32:37 +0800 2014 Puppet (notice): Finished catalog run in 0.04 seconds
Thu Jan 09 05:33:02 +0800 2014 Puppet (info): Loading facts in /var/lib/puppet/lib/facter/fact_apply.rb
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Creating default schedules
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Failed to load library 'ldap' for feature 'ldap'
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Puppet::Type::User::ProviderLdap: feature ldap is missing
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Puppet::Type::User::ProviderUser_role_add: file roleadd does not exist
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Puppet::Type::User::ProviderPw: file pw does not exist
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Puppet::Type::User::ProviderDirectoryservice: file /usr/bin/dscl does not exist
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/state/graphs] (debug): Autorequiring File[/var/lib/puppet/state]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/facts] (debug): Autorequiring File[/var/lib/puppet]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/ssl/certs] (debug): Autorequiring File[/var/lib/puppet/ssl]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/state/last_run_summary.yaml] (debug): Autorequiring File[/var/lib/puppet/state]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/ssl/certs/ca.pem] (debug): Autorequiring File[/var/lib/puppet/ssl/certs]
Thu Jan 09 05:33:02 +0800 2014 /File[/etc/puppet/namespaceauth.conf] (debug): Autorequiring File[/etc/puppet]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/state/last_run_report.yaml] (debug): Autorequiring File[/var/lib/puppet/state]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/ssl/private] (debug): Autorequiring File[/var/lib/puppet/ssl]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/client_data] (debug): Autorequiring File[/var/lib/puppet]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/ssl/crl.pem] (debug): Autorequiring File[/var/lib/puppet/ssl]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/ssl/public_keys] (debug): Autorequiring File[/var/lib/puppet/ssl]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/ssl/certificate_requests] (debug): Autorequiring File[/var/lib/puppet/ssl]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/ssl] (debug): Autorequiring File[/var/lib/puppet]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/client_yaml] (debug): Autorequiring File[/var/lib/puppet]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/state] (debug): Autorequiring File[/var/lib/puppet]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/state/resources.txt] (debug): Autorequiring File[/var/lib/puppet/state]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/state/state.yaml] (debug): Autorequiring File[/var/lib/puppet/state]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/ssl/private_keys] (debug): Autorequiring File[/var/lib/puppet/ssl]
Thu Jan 09 05:33:02 +0800 2014 /File[/var/lib/puppet/lib] (debug): Autorequiring File[/var/lib/puppet]
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Finishing transaction 23661132012600
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Loaded state in 0.03 seconds
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Loaded state in 0.00 seconds
Thu Jan 09 05:33:02 +0800 2014 Puppet (info): Applying configuration version '1389216782'
Thu Jan 09 05:33:02 +0800 2014 /Schedule[daily] (debug): Skipping device resources because running on a host
Thu Jan 09 05:33:02 +0800 2014 /Schedule[monthly] (debug): Skipping device resources because running on a host
Thu Jan 09 05:33:02 +0800 2014 /Schedule[hourly] (debug): Skipping device resources because running on a host
Thu Jan 09 05:33:02 +0800 2014 /Schedule[never] (debug): Skipping device resources because running on a host
Thu Jan 09 05:33:02 +0800 2014 /Schedule[weekly] (debug): Skipping device resources because running on a host
Thu Jan 09 05:33:02 +0800 2014 /Schedule[puppet] (debug): Skipping device resources because running on a host
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Finishing transaction 23661133266940
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Storing state
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Stored state in 0.02 seconds
Thu Jan 09 05:33:02 +0800 2014 Puppet (notice): Finished catalog run in 0.04 seconds
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Finishing transaction 23661132292240
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Received report to process from linux58poc.localdomain
Thu Jan 09 05:33:02 +0800 2014 Puppet (debug): Processing report from linux58poc.localdomain with processor Puppet::Reports::Store
eg. 在本地运行命令,加载一个类,创建motd文件
[iyunv@linux58poc ~]# rm -rf /etc/motd
[iyunv@linux58poc ~]# puppet apply -e "include motd" --noop
notice: /Stage[main]/Motd/File[/etc/motd]/ensure: current_value absent, should be file (noop)
notice: Class[Motd]: Would have triggered 'refresh' from 1 events
notice: Stage[main]: Would have triggered 'refresh' from 1 events
notice: Finished catalog run in 0.17 seconds
[iyunv@linux58poc ~]# puppet apply -e "include motd"
notice: /Stage[main]/Motd/File[/etc/motd]/ensure: defined content as '{md5}b05f87905d7b6d2608f71502906dcaeb'
notice: Finished catalog run in 0.17 seconds
[iyunv@linux58poc ~]# cat /etc/motd
------------a few of facter values-------------
myhostname = linux58poc
eth0_ip = 192.168.100.126
kernel = 2.6.18-308.el5
system release = Red Hat Enterprise Linux Server release 5.8 (Tikanga)
puppetversion = 2.7.23
rubyversion = 1.8.7
....................
....
------------------------------------------------
|
|