有点像木偶新手。我正在尝试递归清除/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下的其他文件外,代码似乎清除了所有文件和目录。有没有想过我在这里做错了什么,或者怎么做才能正确?
最佳答案
您还需要在html目录上设置purge,即:
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
清除。关于linux - puppet -如何清除目录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52502910/