[root@centos7 puppet]# ls
facter-2.4.6-1.el7.x86_64.rpm puppet-3.8.7-1.el7.noarch.rpm puppet-server-3.8.7-1.el7.noarch.rpm
[root@centos7 puppet]# yum install ./puppet-3.8.7-1.el7.noarch.rpm ./facter-2.4.6-1.el7.x86_64.rpm
Dependencies Resolved # 依賴到的相關程式包如下:
=======================================================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================================================
Installing:
facter x86_64 1:2.4.6-1.el7 /facter-2.4.6-1.el7.x86_64 273 k
puppet noarch 3.8.7-1.el7 /puppet-3.8.7-1.el7.noarch 6.3 M
Installing for dependencies:
hiera noarch 1:1.3.4-5.el7 epel 25 k
libselinux-ruby x86_64 2.2.2-6.el7 CDROM 127 k
ruby-augeas x86_64 0.5.0-1.el7 epel 23 k
ruby-shadow x86_64 1.4.1-23.el7 epel 14 k
Transaction Summary
=======================================================================================================================================================================
Install 2 Packages (+4 Dependent packages)
2.puppet程式相關指令
[root@centos7 ~]# 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 v3.8.7
3.puppet apply:
★作用:
Applies a standalone Puppet manifest to the local system.(手動在本地應用自願清單中的配置)
[root@centos7 ~]# mkdir mainfests
[root@centos7 ~]# cd mainfests/
[root@centos7 mainfests]# ls
# 定義group資源
[root@centos7 mainfests]# vim group.pp
group {'mygrp':
name => 'mygrp',
ensure => present,
gid => 3000,
system => false,
}
# 試運作
[root@centos7 mainfests]# puppet apply --verbose --noop group.pp
Notice: Compiled catalog for centos7 in environment production in 0.32 seconds
Info: Applying configuration version '1484056729'
Notice: /Stage[main]/Main/Group[mygrp]/ensure: current_value absent, should be present (noop) #提示目前為absent,應該為present(noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Info: Creating state file /var/lib/puppet/state/state.yaml
Notice: Finished catalog run in 0.06 seconds
[root@centos7 mainfests]# puppet apply --verbose group.pp # 真正執行
Notice: Compiled catalog for centos7 in environment production in 0.28 seconds
Info: Applying configuration version '1484057172'
Notice: /Stage[main]/Main/Group[mygrp]/ensure: created # 已經建立
Notice: Finished catalog run in 0.13 seconds
[root@centos7 mainfests]# tail /etc/group
tcpdump:x:72:
memcached:x:985:
dhcpd:x:177:
zabbix:x:984:
varnish:x:983:
haproxy:x:188:
haclient:x:189:
tomcat:x:982:
puppet:x:52:
mygrp:x:3000: # 建立的組
2.user:
Manage users.(管理使用者)
name:使用者名;
uid: UID;
gid:基本組ID;
groups:附加組,不能包含基本組;
comment:注釋;
expiry:過期時間 ;
home:家目錄;
shell:預設shell類型;
system:是否為系統使用者 ;
ensure:present/absent;
password:加密後的密碼串;
[root@centos7 mainfests]# vim user.pp
group {'mygrp':
name => 'mygrp',
ensure => present,
gid => 3000,
system => false,
}
user {'centos':
name => 'centos',
ensure =>present,
uid =>4000,
groups => 'mygrp',
}
[root@centos7 mainfests]# puppet apply --verbose --noop user.pp
Notice: Compiled catalog for centos7 in environment production in 0.51 seconds
Info: Applying configuration version '1484059044'
Notice: /Stage[main]/Main/Group[mygrp]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Main/User[centos]/ensure: current_value absent, should be present (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.08 seconds
[root@centos7 mainfests]# puppet apply --verbose user.pp
Notice: Compiled catalog for centos7 in environment production in 0.51 seconds
Info: Applying configuration version '1484059058'
Notice: /Stage[main]/Main/Group[mygrp]/ensure: created
Notice: /Stage[main]/Main/User[centos]/ensure: created
Notice: Finished catalog run in 0.32 seconds
Manages files, including their content, ownership, and permissions.
※ensure:Whether the file should exist, and if so what kind of file it should be. Possible values are `present`, `absent`, `file`, `directory`, and `link`.
Executes external commands. Any command in an `exec` resource **must** be able to run multiple times without causing harm --- that is, it must be *idempotent*.(幂等)
**command** (*namevar*):要運作的指令;
cwd:The directory from which to run the command. //定義運作指令前要cd到目錄中去
[root@centos7 mainfests]# cat exec.pp
exec{'mkdir':
command => 'mkdir /tmp/hello.dir',
path => '/bin:/sbin:/usr/bin:/usr/sbin',
creates => '/tmp/hello.dir', # 或者 unless => 'test -d /tmp/hello.dir',也可以
}
[root@centos7 mainfests]# puppet apply --verbose exec.pp
Notice: Compiled catalog for centos7 in environment production in 0.13 seconds
Info: Applying configuration version '1484206815'
Notice: /Stage[main]/Main/Exec[mkdir]/returns: executed successfully
Notice: Finished catalog run in 0.07 seconds
7.cron:
Installs and manages cron jobs. Every cron resource created by Puppet requires a command and at least one periodic attribute (hour, minute, month, monthday, weekday, or special).
command:要執行的任務;
hour:
minute:
monthday:
month:
weekday:
user:添加在哪個使用者之上;
name:cron job的名稱;
[root@centos7 mainfests]# cat cron.pp
cron{'timesync':
command => '/usr/sbin/ntpdate cn.pool.ntp.org &> /dev/null',
ensure =>present,
minute => '*/3',
user => 'root',
}
[root@centos7 mainfests]# puppet apply --verbose cron.pp
Notice: Compiled catalog for centos7 in environment production in 5.38 seconds
Info: Applying configuration version '1484207796'
Notice: /Stage[main]/Main/Cron[timesync]/ensure: created
Notice: Finished catalog run in 0.09 seconds
[root@centos7 mainfests]# crontab -l
# HEADER: This file was autogenerated at 2017-01-12 15:56:42 +0800 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: timesync
*/3 * * * * /usr/sbin/ntpdate cn.pool.ntp.org &> /dev/null
8.notify:
Sends an arbitrary message to the agent run-time log. 發送任意指定資訊到運作日志中
message:資訊内容
[root@centos7 mainfests]# cat notify.pp
notify{'hello':
message => 'hello there',
name => 'pig head',
}
[root@centos7 mainfests]# puppet apply --verbose notify.pp
Notice: Compiled catalog for centos7 in environment production in 0.11 seconds
Info: Applying configuration version '1484208626'
Notice: hello there
Notice: /Stage[main]/Main/Notify[hello]/message: defined 'message' as 'hello there'
Notice: Finished catalog run in 0.04 seconds