我正在尝试使用人偶添加cron条目。我的课堂上有以下代码:
cron { 'puppet-apply':
ensure => present,
command => "/usr/bin/mycommand",
user => root,
hour => '14',
minute => '49',
require => File['mycommand'],
}
mycommand
是同一类中的另一个定义。当运行puppet时,会将mycommand
可执行文件正确添加到/usr/bin
,但是我看不到在/etc/crontab
(或其他任何地方)中创建的crontab条目。
我在这里想念什么?如何获取它来创建crontab条目?
您的代码工作正常,我怀疑您只是误解了Puppet如何管理cron标签。
如果使用最新的Puppet,则cron逻辑的源代码为here。注意操作系统类型here使用的实际文件:
CRONTAB_DIR = case Facter.value('osfamily')
when 'Debian', 'HP-UX', 'Solaris'
'/var/spool/cron/crontabs'
when %r{BSD}
'/var/cron/tabs'
when 'Darwin'
'/usr/lib/cron/tabs/'
else
'/var/spool/cron'
end
所以给出这样的代码:
file { 'mycommand':
path => "/usr/bin/mycommand",
content => "#!/usr/bin/bash\necho hello world",
}
cron { 'puppet-apply':
ensure => present,
command => "/usr/bin/mycommand",
user => root,
hour => '14',
minute => '49',
require => File['mycommand'],
}
如果在CentOS 7上以root身份应用:
[root@centos-72-x64 ~]# puppet apply /tmp/apply_manifest.pp
Notice: Compiled catalog for centos-72-x64.macquarie.local in environment production in 0.05 seconds
Notice: /Stage[main]/Main/File[mycommand]/ensure: defined content as '{md5}8d9f82443e4fb78b8316c17174182d16'
Notice: /Stage[main]/Main/Cron[puppet-apply]/ensure: created
Notice: Applied catalog in 0.04 seconds
您将拥有预期的crontab:
[root@centos-72-x64 ~]# crontab -l
# HEADER: This file was autogenerated at 2019-11-09 03:55:09 +0000 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: puppet-apply
49 14 * * * /usr/bin/mycommand
并且实际修改的文件在/var/spool/cron
中:
[root@centos-72-x64 ~]# find /var/spool/cron
/var/spool/cron
/var/spool/cron/root
[root@centos-72-x64 ~]# cat /var/spool/cron/root
# HEADER: This file was autogenerated at 2019-11-09 03:55:09 +0000 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: puppet-apply
49 14 * * * /usr/bin/mycommand