当前位置: 首页 > news >正文

Puppet apply命令参数介绍(五)

Puppet apply 命令参数介绍

之前说过puppet的两种运行方式,第一种:c/s结构,第二种:单机运行。apply就是单独执行本地*.pp文件的代码工具,通常用于本地测试调试puppet代码.


puppet apply常用参数:

[root@sh-proxy2 ~]# puppet apply -h
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|--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 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 setting that's valid in the configuration
file is also a valid long argument. For example, 'tags' is a
valid setting, 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:#提供退出代码的信息,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.txt
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 安装apache.

[root@sh-proxy2 ~]# rpm -qa httpd
[root@sh-proxy2 ~]# vim httpd.pp
[root@sh-proxy2 ~]# cat httpd.pp 
package {"httpd":
ensure => true,
}
#应用本地httpd.pp代码文件
[root@sh-proxy2 ~]# puppet apply httpd.pp 
Notice: Compiled catalog for sh-proxy2.localdomain in environment production in 0.18 seconds
Notice: /Stage[main]/Main/Package[httpd]/ensure: created
Notice: Finished catalog run in 12.67 seconds
#确认已经安装
[root@sh-proxy2 ~]# rpm -qa httpd
httpd-2.2.15-60.el6.centos.5.x86_64

--verbose参数:

[root@sh-proxy2 ~]# puppet apply httpd.pp --verbose
Notice: Compiled catalog for sh-proxy2.localdomain in environment production in 0.12 seconds
Info: Applying configuration version '1504671755'
Notice: /Stage[main]/Main/Package[httpd]/ensure: created
Notice: Finished catalog run in 3.51 seconds

--execute参数:

#test模块下test类.
[root@sh-proxy2 manifests]# pwd
/etc/puppet/modules/test/manifests
[root@sh-proxy2 manifests]# ls
init.pp
#模块下必须有init.pp文件声明一个和模块同名的类.
[root@sh-proxy2 manifests]# cat init.pp 
class test {
    package {"httpd":
        ensure => true,
    }
}

-e等同于--execute参数参数,类要想使用必须声明类使用include.

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


举例2:

notify 资源输出命令. 

注意:puppet中的notify命令和shell中的echo相似,都是将代码执行结果通过屏幕终端打印出来.

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


相关文章:

  • Spring中Bean的depends-on属性
  • esxi嵌套华为Fusioncomputer安装VRM几个关键步骤。
  • SQL Server 中的6种事务隔离级别简单总结
  • 《区块链原理、设计与应用》一3.1 应用场景概览
  • json数据导出excel
  • spring cloud 学习(9) - turbine stream无法在eureka注册的解决办法
  • 什么是Ubuntu的云计算?
  • 高危预警!移动设备安全面临的5大新型威胁
  • IOCP vs EPOLL
  • 体验Windows Mobile 6.5 (模拟器)
  • 这是要逆天么,看我控制台程序玩Microsoft XPS Document 打印
  • Spring Cloud中负载均衡器概览
  • 文件特殊权限:SUID,SGID,SBIT
  • 11.03 在外链接中用OR逻辑
  • 将文件名从1变为000001
  • 分享一款快速APP功能测试工具
  • “寒冬”下的金三银四跳槽季来了,帮你客观分析一下局面
  • Codepen 每日精选(2018-3-25)
  • mockjs让前端开发独立于后端
  • Python_OOP
  • quasar-framework cnodejs社区
  • SpiderData 2019年2月23日 DApp数据排行榜
  • 解决iview多表头动态更改列元素发生的错误
  • 设计模式 开闭原则
  • 使用阿里云发布分布式网站,开发时候应该注意什么?
  • 体验javascript之美-第五课 匿名函数自执行和闭包是一回事儿吗?
  • hi-nginx-1.3.4编译安装
  • Linux权限管理(week1_day5)--技术流ken
  • #{} 和 ${}区别
  • #1014 : Trie树
  • #我与Java虚拟机的故事#连载11: JVM学习之路
  • (003)SlickEdit Unity的补全
  • (2020)Java后端开发----(面试题和笔试题)
  • (echarts)echarts使用时重新加载数据之前的数据存留在图上的问题
  • (pojstep1.3.1)1017(构造法模拟)
  • (附源码)spring boot儿童教育管理系统 毕业设计 281442
  • (强烈推荐)移动端音视频从零到上手(上)
  • (原創) 如何刪除Windows Live Writer留在本機的文章? (Web) (Windows Live Writer)
  • (转)Java socket中关闭IO流后,发生什么事?(以关闭输出流为例) .
  • (最优化理论与方法)第二章最优化所需基础知识-第三节:重要凸集举例
  • ****Linux下Mysql的安装和配置
  • .NET 5种线程安全集合
  • .Net Winform开发笔记(一)
  • .Net 垃圾回收机制原理(二)
  • .NET委托:一个关于C#的睡前故事
  • @select 怎么写存储过程_你知道select语句和update语句分别是怎么执行的吗?
  • [2021ICPC济南 L] Strange Series (Bell 数 多项式exp)
  • [android] 切换界面的通用处理
  • [Angular] 笔记 20:NgContent
  • [BUUCTF NewStarCTF 2023 公开赛道] week4 crypto/pwn
  • [JS]JavaScript 简介
  • [LeetCode] 2.两数相加
  • [leetcode]56. Merge Intervals归并区间
  • [LitCTF 2023]Http pro max plus
  • [Oh My C++ Diary]怎样用cmd运行exe控制台程序