puppet的常用语法

检查语法错误

 puppet parser validate xx.pp

在客户端测试但是不应用

puppet agent --test --noop

基于安全的考虑,使用预签名证书

 puppet cert --generate <hostname> 
 使用如下命令为 client1.example.com 生成预签名证书:

 puppet cert --generate client1.example.com
Puppet 现在将为客户端 client1.example.com 生成并签署客户端证书。 传输三个所需的文件到新的客户端:包括客户端私钥、客户端证书和 CA 证书。 这三个文件位于: /etc/puppet/ssl/private_keys/client1.example.com.pem
/etc/puppet/ssl/certs/client1.example.com.pem
/etc/puppet/ssl/certs/ca.pem
复制上述三个文件到客户端相应的目录下,Puppet 会自动进行身份验证从而省略证书请求这一步骤。 值得注意的是 Puppet 的 SSL 证书的位置依赖于 puppet.conf 中的 ssldir 设置。

查看帮助

puppet   --help  #很重要,可以了解puppet的语法,使用
 [root@agent1 src]# puppet help

 Usage: puppet <subcommand> [options] <action> [options]

 Available subcommands:

   agent             The puppet agent daemon
apply Apply Puppet manifests locally
ca Local Puppet Certificate Authority management.
catalog Compile, save, view, and convert catalogs.
cert Manage certificates and requests
certificate Provide access to the CA for certificate management.
certificate_request Manage certificate requests.
certificate_revocation_list Manage the list of revoked certificates.
config Interact with Puppet's settings.
describe Display help about resource types
device Manage remote network devices
doc Generate Puppet documentation and references
facts Retrieve and store facts.
file Retrieve and store files in a filebucket
filebucket Store and retrieve files in a filebucket
help Display Puppet help.
inspect Send an inspection report
instrumentation_data Manage instrumentation listener accumulated data. DEPRECATED.
instrumentation_listener Manage instrumentation listeners. DEPRECATED.
instrumentation_probe Manage instrumentation probes. Deprecated
key Create, save, and remove certificate keys.
kick Remotely control puppet agent
man Display Puppet manual pages.
master The puppet master daemon
module Creates, installs and searches for modules on the Puppet Forge.
node View and manage node definitions.
parser Interact directly with the parser.
plugin Interact with the Puppet plugin system.
queue Deprecated queuing daemon for asynchronous storeconfigs
report Create, display, and submit reports.
resource The resource abstraction layer shell
resource_type View classes, defined resource types, and nodes from all manifests.
secret_agent Mimics puppet agent.
status View puppet server status. See 'puppet help <subcommand> <action>' for help on a specific subcommand action.
See 'puppet help <subcommand>' for help on a specific subcommand.

Puppet 的 filebucket备份

1,通常使用的办法(官方教材)

 cat   /etc/puppet/manifests/site.pp
filebucket { 'main':
path => false, # This is required for remote filebuckets.#只在server端备份,client不备份
server => 'puppet.example.com', # Optional; defaults to the configured puppet master.
} File { backup => main, } #全局生效Puppet 对所有的文件执行这样的默认备份策略
说明下path
The path to the local filebucket; defaults to the value of the clientbucketdir setting. To use a remote filebucket, you must set this attribute to false.
path默认是在client里 默认备份是在/var/lib/puppet/clientbucket/里,加上path=false是说明备份在server端

2自定义备份在当前目录下

如下这样在定义文件服务的时候加个:

 file { "/etc/sudoers":
mode => "",
source => "puppet:///modules/admin/sudoers",
backup => ".bak", #增加的
}

同步后。就会在client端原始目录下创建备份文件

3 什么也不配置,会在client端生成备份文件在/var/lib/puppet/clientbucket/

[root@agent1 ~]# ls -l /var/lib/puppet/clientbucket/d///d//c/d//d41d8cd98f00b204e9800998ecf8427e/
total
-r--r-----. root root Jan : contents
-rw-r-----. root root Jan : paths

简单说下:

contens 文件的内容即为原始文件,paths 文件的内容即为原始文件的路径。

对于第三种情况下的恢复

创建检索filebucket

 find /var/lib/puppet/clientbucket -name paths -exec cat {} \; -execdir pwd \; -exec date +"%F %T" \; -exec echo \; 

会查找出所有的备份文件

 /etc/sudoers
/var/lib/puppet/clientbucket/c///d//a/a//
c07d0aa2d43d58ea7b5c5307f532a0b1
-- :: /etc/sudoers
/var/lib/puppet/clientbucket/////e///a/1090e28a70ebaae872c2e
c78894f49eb
-- ::
上一篇:各种Markdown处理器的列表


下一篇:JS手机访问PC端网站自动跳转到手机端网站