简单使用
安装
quick
- Puppet的一些概念 https://docs.puppet.com/puppet/latest/reference/lang_summary.html
- 快速入门 https://docs.puppet.com/puppet/4.4/reference/quick_start.html
simple example
https://docs.puppet.com/puppet/4.4/reference/quick_start_user_group.html
puppet apply -e "user { 'jargyle': ensure => present, }"
puppet apply -e "group { 'web': ensure => present, }"
puppet resource -e group web
puppet resource -e user jargyle
cd /etc/puppetlabs/code/environments/production/manifests
[root@cu2 manifests]# vi site.pp
group { 'web':
ensure => present, # absent, present
}
user { 'jargyle':
ensure => present,
home => '/home/jargyle',
shell => '/bin/bash',
password_max_age => '99999',
password_min_age => '0',
groups => web,
}
puppet parser validate site.pp
module helloworld
- https://docs.puppet.com/puppet/4.4/reference/quick_start_helloworld.html
- https://docs.puppet.com/puppet/4.4/reference/quick_start_adding_classes_nix.html
https://docs.puppet.com/puppet/4.4/reference/modules_metadata.html
[root@cu2 modules]# mkdir -p helloworld/manifests [root@cu2 manifests]# vi init.pp class helloworld { notify { ‘Hello World’: } } [root@cu2 manifests]# vi motd.pp class helloworld::motd {
file { '/etc/motd': owner => 'root', group => 'root', mode => '0644', content => "Hello World!\n", }
}
[root@cu2 manifests]# vi ../../../manifests/site.pp node default { class { ‘helloworld’: } class { ‘helloworld::motd’: } } [root@cu2 manifests]# puppet parser validate ../../../manifests/site.pp
[root@cu2 manifests]# cat site.pp node default {
file { ‘/etc/cron.hourly’: ensure => directory, }
package { [‘ntp’, ‘ntpdate’]: ensure => installed, }
/ if $fqdn != ‘cu2.esw.cn’ { class { ‘ntp’: runmode => ‘cron’, cron_command => ‘ntpdate cu2’, require => [ Package[‘ntp’, ‘ntpdate’], File[‘/etc/cron.hourly’] ], } } /
– hosts / 多网卡的时刻需要注意 class { ‘hosts’: dynamic_mode => true, dynamic_ip => $::ipaddress_bond0 } / if $fqdn =~ /.*.ds.ctyun/ { class { ‘hosts’: dynamic_mode => true, } }
cron {‘run-puppet’: command => “source /etc/profile; puppet agent –test >/tmp/puppet-cron.log 2>&1”, minute => inline_template(‘<%= @hostname.hash.abs % 60 %>’), }
file{‘/etc/puppetlabs/mcollective/facts.yaml’: owner => root, group => root, mode => ‘400’, loglevel => debug, # reduce noise in Puppet reports content => inline_template(“<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime_seconds|timestamp|free)/ }.to_yaml %>”), # exclude rapidly changing facts } }
modules install
https://docs.puppet.com/puppet/latest/reference/modules_installing.html
The full name of a Forge module is formatted as username-modulename.
https://docs.puppet.com/puppet/latest/reference/modules_fundamentals.html#writing-modules
[root@cu2 code]# cd environments/production/modules/
[root@cu2 modules]# puppet module generate --skip-interview winse-hello
[root@cu2 modules]# puppet module install puppetlabs-stdlib
Notice: Preparing to install into /etc/puppetlabs/code/environments/production/modules ...
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppetlabs/code/environments/production/modules
└── puppetlabs-stdlib (v4.11.0)
[root@cu2 modules]# puppet module list
/etc/puppetlabs/code/environments/production/modules
├── puppetlabs-stdlib (v4.11.0)
└── winse-hello (v0.1.0)
/etc/puppetlabs/code/modules (no modules installed)
/opt/puppetlabs/puppet/modules (no modules installed)
sudo puppet module install ~/puppetlabs-apache-0.10.0.tar.gz –ignore-dependencies
Listing Installed Modules Use the module tool’s list action to see which modules you have installed (and which directory they’re installed in).
Use the –tree option to view the modules arranged by dependency instead of by location on disk.
puppet4 插件同步选项默认是开启的 pluginsync=true,不需要额外的操作。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
- ntp
docker不能修改系统时间!!
https://github.com/example42/puppet-ntp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
- sudo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
上面简单的列出了 puppet 的简单使用,但是如果有大文件。。。
文件
- https://docs.puppet.com/guides/file_serving.html
- https://docs.puppet.com/puppet/latest/reference/config_file_fileserver.html
- https://docs.puppet.com/guides/scaling.html rsync or NFS
- https://ask.puppet.com/question/14565/can-we-transfer-a-4gb-patch-file-to-agents-using-puppet-fileserver/
- https://wizardforcel.gitbooks.io/puppet-27-cookbook/content/86.html
有时可为了传输临时的几个文件,要个单独整一个module比较麻烦,可以使用fileserver直接在site.pp中进行更新同步处理。
- 添加fileserver.conf配置
1 2 3 |
|
同时修改files目录的权限: chown -R puppet files
- 在site.pp中添加更新文件的配置
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
文件比较多时,可以使用循环:
- https://docs.puppet.com/puppet/latest/reference/lang_iteration.html
- https://docs.puppet.com/puppet/latest/reference/lang_resources_advanced.html#arrays-of-titles
1 2 3 4 5 6 7 8 9 |
|
或者
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
模板
- https://docs.puppet.com/puppet/latest/reference/lang_template.html
- https://docs.puppet.com/puppet/latest/reference/lang_template_epp.html
- https://docs.puppet.com/puppet/latest/reference/lang_template_erb.html https://docs.puppet.com/puppet/latest/reference/modules_fundamentals.html
https://docs.puppet.com/puppet/latest/reference/lang_relationships.html#ordering-and-notification
节点定义
- https://docs.puppet.com/puppet/4.4/reference/lang_node_definitions.html
- https://docs.puppet.com/guides/external_nodes.html http://activemq.apache.org/getting-started.html