这里有个木偶新手。我试图递归清除/ var / www下的所有文件和目录,除了保留一个文件(/var/www/html/appicon.ico)。这是我的代码:
file {'/var/www':
ensure => directory,
recurse => true,
purge => true,
force => true,
require => Package['httpd'],
subscribe => Package['httpd']
} ->
file {'/var/www/html':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755'
} ->
file {'/var/www/html/appicon.ico':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => ''
}
该代码确实清除了所有文件和目录,但/ var / www / html下的其他文件除外。有什么想法我在这里做错了或者如何正确地做到这一点?
答案 0 :(得分:0)
您还需要在html目录上设置清除,即:
file {'/var/www':
ensure => directory,
recurse => true,
purge => true,
force => true,
require => Package['httpd'],
subscribe => Package['httpd'],
} ->
file {'/var/www/html':
ensure => directory,
recurse => true, # note here
purge => true, #
owner => 'root',
group => 'root',
mode => '0755'
} ->
file {'/var/www/html/appicon.ico':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => ''
}
在Puppet清单中明确包含文件/目录可“保护”文件/目录免遭其父目录上设置的purge => true, recurse => true
清除。