Puppet 和 hiera,如何应用更改?
Puppet and hiera,how to apply changes?
我想通过 puppet 更新 cron。
直到今天我只用工头申请
并且从未使用过hiera。
关注此 howto
首先,我为 hiera
创建了目录
cd /etc/puppet && mkdir -p hieradata/development hieradata/production/domains hieradata/production/fqdns hieradata/production/OBSOLETE hieradata/production/roles
然后我编辑hiera.yaml
:backends:
- yaml :yaml: :datadir: '/etc/puppet/hieradata/%{::environment}' :hierarchy:
- fqdns/%{::fqdn}
- roles/%{::role}
- domains/%{::domain}
- common
然后我输入common.yaml
## Cron module
cron::enable: true # on startup
cron::ensure: true # running
cron::crontab_path: /etc/crontab
puppetheader: Managed by Puppet @ site.priv
cron::crontab_vars_hsh:
SHELL: /usr/bin/sh
PATH: /sbin:/bin:/usr/sbin:/usr/bin
MAILTO: ""
HOME: /root
cron::crontab_site_job_hsh:
'check scripts in cron.hourly, cron.daily, cron.weekly and cron.monthly':
- "*/35 * * * * script.sh >/dev/null 2>&1"
Hiera 似乎有效
hiera -c ../hiera.yaml cron::ensure
hiera cron::ensure
true
但是在 puppet agent -t 之后...没有任何变化
/etc/crontab 是系统默认值。
我也做了
puppet apply -e 'include cron' --hiera_config=/etc/puppet/hiera.yaml --verbose --debug
和return
Debug: Scope(Class[Cron::Crontab::Config]): Retrieving template cron/crontab.erb
Debug: template[/etc/puppet/environments/production/modules/cron/templates/crontab.erb]: Bound template variables for /etc/puppet/environments/production/modules/cron/templates/crontab.erb in 0.00 seconds
Warning: Variable access via 'puppetheader' is deprecated. Use '@puppetheader' instead. template[/etc/puppet/environments/production/modules/cron/templates/crontab.erb]:1
(at /usr/share/ruby/vendor_ruby/puppet/parser/templatewrapper.rb:77:in `method_missing')
Error: Failed to parse template cron/crontab.erb:
Filepath: /usr/share/ruby/vendor_ruby/puppet/parser/templatewrapper.rb
Line: 82
Detail: Could not find value for 'package_name' at /etc/puppet/environments/production/modules/cron/templates/crontab.erb:2
at /etc/puppet/environments/production/modules/cron/manifests/init.pp:47 on node server.example.com
Error: Failed to parse template cron/crontab.erb:
Filepath: /usr/share/ruby/vendor_ruby/puppet/parser/templatewrapper.rb
Line: 82
Detail: Could not find value for 'package_name' at /etc/puppet/environments/production/modules/cron/templates/crontab.erb:2
at /etc/puppet/environments/production/modules/cron/manifests/init.pp:47 on node centos.example.com
我想念什么?
edit1:我添加了.erb
## <%= puppetheader %>
# for <%= package_name %>
<% if (!crontab_vars_hsh.empty?) -%>
## Variables
<% crontab_vars_hsh.sort.each do |key,val| -%>
<%= key %>=<%= val %>
<% end -%>
<% end -%>
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * username command-to-be-executed
<% if (!crontab_site_job_hsh.empty?) -%>
## Site Wide Jobs
<% crontab_site_job_hsh.sort.each do |key,val| -%>
# <%= key %>
<% val.each do |croncmd| -%>
<%= croncmd %>
<% end -%>
<% end -%>
<% end -%>
<% if (!crontab_node_job_hsh.empty?) -%>
## Node Specific Jobs
<% crontab_node_job_hsh.sort.each do |key,val| -%>
# <%= key %>
<% val.each do |croncmd| -%>
<%= croncmd %>
<% end -%>
<% end -%>
<% end -%>
Cron 类型
需要 cron was a Puppet generic type up to Puppet 5, there's no need to install special module. For Puppet 6 and later cron_core
module(资源已移至外部模块),例如
puppet module install puppetlabs-cron_core
用法应该是一样的
cron { 'myscript':
command => '/usr/bin/python myscript.py',
user => 'root',
minute => '30',
hour => '0',
}
如果您想使用 Hiera yaml,请声明一些作业
cron_jobs:
'myscript':
command: 'm/usr/bin/python myscript.py'
minute: 30
hour: 0
date: '*'
month: '*'
weekday: '*'
user: root
在 Puppet 代码中:
create_resources (cron, lookup('cron_jobs', Hash, undef, {}))
Cron 模块
cron
module 不在内部使用 Puppet 的 cron
类型,它直接管理磁盘上的配置文件。因此 API 可能略有不同:
---
cron::job:
'myscript':
command: 'm/usr/bin/python myscript.py'
minute: 30
hour: 0
date: '*'
month: '*'
weekday: '*'
user: root
并且不要忘记在节点定义的某处添加 include cron
。
我想通过 puppet 更新 cron。 直到今天我只用工头申请 并且从未使用过hiera。 关注此 howto 首先,我为 hiera
创建了目录cd /etc/puppet && mkdir -p hieradata/development hieradata/production/domains hieradata/production/fqdns hieradata/production/OBSOLETE hieradata/production/roles
然后我编辑hiera.yaml
:backends:
- yaml :yaml: :datadir: '/etc/puppet/hieradata/%{::environment}' :hierarchy:
- fqdns/%{::fqdn}
- roles/%{::role}
- domains/%{::domain}
- common
然后我输入common.yaml
## Cron module
cron::enable: true # on startup
cron::ensure: true # running
cron::crontab_path: /etc/crontab
puppetheader: Managed by Puppet @ site.priv
cron::crontab_vars_hsh:
SHELL: /usr/bin/sh
PATH: /sbin:/bin:/usr/sbin:/usr/bin
MAILTO: ""
HOME: /root
cron::crontab_site_job_hsh:
'check scripts in cron.hourly, cron.daily, cron.weekly and cron.monthly':
- "*/35 * * * * script.sh >/dev/null 2>&1"
Hiera 似乎有效
hiera -c ../hiera.yaml cron::ensure
hiera cron::ensure
true
但是在 puppet agent -t 之后...没有任何变化 /etc/crontab 是系统默认值。 我也做了
puppet apply -e 'include cron' --hiera_config=/etc/puppet/hiera.yaml --verbose --debug
和return
Debug: Scope(Class[Cron::Crontab::Config]): Retrieving template cron/crontab.erb
Debug: template[/etc/puppet/environments/production/modules/cron/templates/crontab.erb]: Bound template variables for /etc/puppet/environments/production/modules/cron/templates/crontab.erb in 0.00 seconds
Warning: Variable access via 'puppetheader' is deprecated. Use '@puppetheader' instead. template[/etc/puppet/environments/production/modules/cron/templates/crontab.erb]:1
(at /usr/share/ruby/vendor_ruby/puppet/parser/templatewrapper.rb:77:in `method_missing')
Error: Failed to parse template cron/crontab.erb:
Filepath: /usr/share/ruby/vendor_ruby/puppet/parser/templatewrapper.rb
Line: 82
Detail: Could not find value for 'package_name' at /etc/puppet/environments/production/modules/cron/templates/crontab.erb:2
at /etc/puppet/environments/production/modules/cron/manifests/init.pp:47 on node server.example.com
Error: Failed to parse template cron/crontab.erb:
Filepath: /usr/share/ruby/vendor_ruby/puppet/parser/templatewrapper.rb
Line: 82
Detail: Could not find value for 'package_name' at /etc/puppet/environments/production/modules/cron/templates/crontab.erb:2
at /etc/puppet/environments/production/modules/cron/manifests/init.pp:47 on node centos.example.com
我想念什么?
edit1:我添加了.erb
## <%= puppetheader %>
# for <%= package_name %>
<% if (!crontab_vars_hsh.empty?) -%>
## Variables
<% crontab_vars_hsh.sort.each do |key,val| -%>
<%= key %>=<%= val %>
<% end -%>
<% end -%>
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * username command-to-be-executed
<% if (!crontab_site_job_hsh.empty?) -%>
## Site Wide Jobs
<% crontab_site_job_hsh.sort.each do |key,val| -%>
# <%= key %>
<% val.each do |croncmd| -%>
<%= croncmd %>
<% end -%>
<% end -%>
<% end -%>
<% if (!crontab_node_job_hsh.empty?) -%>
## Node Specific Jobs
<% crontab_node_job_hsh.sort.each do |key,val| -%>
# <%= key %>
<% val.each do |croncmd| -%>
<%= croncmd %>
<% end -%>
<% end -%>
<% end -%>
Cron 类型
需要cron was a Puppet generic type up to Puppet 5, there's no need to install special module. For Puppet 6 and later cron_core
module(资源已移至外部模块),例如
puppet module install puppetlabs-cron_core
用法应该是一样的
cron { 'myscript':
command => '/usr/bin/python myscript.py',
user => 'root',
minute => '30',
hour => '0',
}
如果您想使用 Hiera yaml,请声明一些作业
cron_jobs:
'myscript':
command: 'm/usr/bin/python myscript.py'
minute: 30
hour: 0
date: '*'
month: '*'
weekday: '*'
user: root
在 Puppet 代码中:
create_resources (cron, lookup('cron_jobs', Hash, undef, {}))
Cron 模块
cron
module 不在内部使用 Puppet 的 cron
类型,它直接管理磁盘上的配置文件。因此 API 可能略有不同:
---
cron::job:
'myscript':
command: 'm/usr/bin/python myscript.py'
minute: 30
hour: 0
date: '*'
month: '*'
weekday: '*'
user: root
并且不要忘记在节点定义的某处添加 include cron
。