设为首页 收藏本站
查看: 1253|回复: 0

[经验分享] puppet实战-puppet apply命令的中文帮助信息详解

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-4-21 10:04:44 | 显示全部楼层 |阅读模式
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
....................
....
------------------------------------------------


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-18022-1-1.html 上篇帖子: puppet实战-puppet agent命令的中文帮助信息详解 下篇帖子: puppet实战-puppet cert命令的中文帮助信息详解 中文 信息
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表