Puppet apply命令參數介紹(五)

來源:互聯網
上載者:User

標籤:puppet apply 命令參數介紹

Puppet apply 命令參數介紹

之前說過puppet的兩種運行方式,第一種:c/s結構,第二種:單機運行。apply就是單獨執行本地*.pp檔案的代碼工具,通常用於本地測試調試puppet代碼.


puppet apply常用參數:

[[email protected] ~]# puppet apply -hpuppet-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|--loadclasses]  [-l|--logdest syslog|eventlog|<FILE>|console] [--noop]  [--catalog <catalog>] [--write-catalog-summary] <file>DESCRIPTION-----------This is the standalone puppet execution tool; use it to applyindividual manifests.When provided with a modulepath, via command line or config file, puppetapply can effectively mimic the catalog that would be served by puppetmaster with access to the same modules, although there are some subtledifferences. When combined with scheduling and an automated system forpushing manifests, this can be used to implement a serverless Puppetsite.Most users should use ‘puppet agent‘ and ‘puppet master‘ for site-widemanifests.OPTIONS-------Note that any setting that‘s valid in the configurationfile is also a valid long argument. For example, ‘tags‘ is avalid setting, so you can specify ‘--tags <class>,<tag>‘as an argument.See the configuration file documentation athttp://docs.puppetlabs.com/references/stable/configuration.html for thefull list of acceptable parameters. A commented list of allconfiguration options can also be generated by running puppet with‘--genconfig‘.* --debug:        #偵錯模式,輸出執行過程的調試資訊  Enable full debugging.* --detailed-exitcodes:#提供結束代碼的資訊,2表示代碼有變化,4表示失敗,6兩者都有.  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:    #載入任何儲存的類,通常puppet agent類配置緩衝在/etc/puppet/classes.txt,設定這個參數導致所有選擇的類將設定在puppet 清單中.  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 log messages. Choose between ‘syslog‘ (the POSIX syslog  service), ‘eventlog‘ (the Windows Event Log), ‘console‘, or the path to a log  file. Defaults to ‘console‘.  A path ending with ‘.json‘ will receive structured output in JSON format. The  log file will not have an ending ‘]‘ automatically written to it due to the  appending nature of logging. It must be appended manually to make the content  valid JSON.* --noop:        #只運行代碼,不應用catalog  Use ‘noop‘ mode where Puppet runs in a no-op or dry-run mode. This  is useful for seeing what changes Puppet will make without actually  executing the changes.* --execute:        #執行一段puppet代碼  Execute a specific piece of Puppet code* --test:        #啟用測試  Enable the most common options used for testing. These are ‘verbose‘,  ‘detailed-exitcodes‘ and ‘show_diff‘.* --verbose:        #列印詳細執行過程  Print extra information.* --catalog:#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.* --write-catalog-summary        #編譯完catalog後,將資源清單和類列表儲存到節點。  After compiling the catalog saves the resource list and classes list to the node  in the state directory named classes.txt and resources.txtEXAMPLE-------    $ puppet apply -l /tmp/manifest.log manifest.pp    $ puppet apply --modulepath=/root/dev/modules -e "include ntpd::server"    $ puppet apply --catalog catalog.jsonAUTHOR------Luke KaniesCOPYRIGHT---------Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License


舉例:

本地使用puppet 安裝apache.

[[email protected] ~]# rpm -qa httpd[[email protected] ~]# vim httpd.pp[[email protected] ~]# cat httpd.pp package {"httpd":ensure => true,}#應用本地httpd.pp代碼檔案[[email protected] ~]# puppet apply httpd.pp Notice: Compiled catalog for sh-proxy2.localdomain in environment production in 0.18 secondsNotice: /Stage[main]/Main/Package[httpd]/ensure: createdNotice: Finished catalog run in 12.67 seconds#確認已經安裝[[email protected] ~]# rpm -qa httpdhttpd-2.2.15-60.el6.centos.5.x86_64

--verbose參數:

[[email protected] ~]# puppet apply httpd.pp --verboseNotice: Compiled catalog for sh-proxy2.localdomain in environment production in 0.12 secondsInfo: Applying configuration version ‘1504671755‘Notice: /Stage[main]/Main/Package[httpd]/ensure: createdNotice: Finished catalog run in 3.51 seconds

--execute參數:

#test模組下test類.[[email protected] manifests]# pwd/etc/puppet/modules/test/manifests[[email protected] manifests]# lsinit.pp#模組下必須有init.pp檔案聲明一個和模組同名的類.[[email protected] manifests]# cat init.pp class test {    package {"httpd":        ensure => true,    }}

-e等同於--execute參數參數,類要想使用必須聲明類使用include.

[[email protected] manifests]# puppet apply -e "include test"Notice: Compiled catalog for sh-proxy2.localdomain in environment production in 0.15 secondsNotice: /Stage[main]/Test/Package[httpd]/ensure: createdNotice: Finished catalog run in 3.11 seconds[[email protected] manifests]# rpm -qa httpdhttpd-2.2.15-60.el6.centos.5.x86_64


舉例2:

notify 資源輸出命令. 

注意:puppet中的notify命令和shell中的echo相似,都是將代碼執行結果通過螢幕終端列印出來.

[[email protected] ~]# cat test.pp notify {"hello world":}[[email protected] ~]# puppet apply test.pp Notice: Compiled catalog for sh-proxy2.localdomain in environment production in 0.02 secondsNotice: hello worldNotice: /Stage[main]/Main/Notify[hello world]/message: defined ‘message‘ as ‘hello world‘Notice: Finished catalog run in 0.01 seconds


本文出自 “青衫解衣” 部落格,請務必保留此出處http://215687833.blog.51cto.com/6724358/1963705

Puppet apply命令參數介紹(五)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.