我试图通过Puppet从Windows PATH中删除所有版本的java 我将用%JAVA_HOME%\ bin替换它。
以下是当前代码:
include windows_path
define obsolete_java {
windows_path {
$name:
ensure => absent,
directory => "C:\\Program Files\\Java\\$name\\bin";
}
}
define windows_java::setup (
$ensure = 'present',
$source = undef,
$file = undef,
$package = undef ) {
case $::osfamily {
Windows : { $supported = true }
default : { fail("The ${module_name} module is not supported on ${::osfamily} based systems") }
}
# Validate parameters
if ($source == undef) {
fail('source parameter must be set')
}
if ($file == undef) {
fail('file parameter must be set')
}
if ($package == undef) {
fail('package parameter must be set')
}
# Validate input values for $ensure
if !($ensure in ['present', 'absent']) {
fail('ensure must either be present or absent')
}
if ($caller_module_name == undef) {
$mod_name = $module_name
} else {
$mod_name = $caller_module_name
}
if ($ensure == 'present'){
# ensures main directory exists
file {'C:\Program Files\Java':
ensure => directory,
}
# copies source executable over
file { "C:\\Program Files\\Java\\$source":
ensure => present,
source => "puppet:///extra_files/java/windows/$source",
before => Package["$package"],
source_permissions => ignore,
}
# Name of package must match name when installed
package { "$package":
ensure => installed,
source => "C:\\Program Files\\java\\$source",
install_options => '/s',
}
# sets JAVA_HOME. If already existant, replaces it.
windows_env { "JAVA_HOME=C:\\Program Files\\Java\\$file":
mergemode => clobber,
}
# removes previous Java from path
obsolete_java {'jdk1.7.0_51':}
# Adds JAVA_HOME to the path.
windows_path {'javaPath':
ensure => present,
directory => "%JAVA_PATH%\bin",
}
} else {
package { 'remove-package':
name => "$package",
ensure => absent,
}
windows_env { 'JAVA_HOME':
ensure => 'absent',
mergemode => clobber,
}
windows_path {'remove_java_path':
ensure => absent,
directory => "C:\\Program Files\\Java\\$file\\bin",
}
}
}
具体做法是:
define obsolete_java {
windows_path {
$name:
ensure => absent,
directory => "C:\\Program Files\\Java\\$name\\bin";
}
}
在这里打电话:
# removes previous Java from path
obsolete_java {'jdk1.7.0_51':}
是否可以删除它在以下位置找到的任何内容:C:\ Program Files \ Java \ any_jdk bin?
编辑:更重要的是,我可以强制它找到包含单词" java"的任何目录。并从PATH中删除它?
答案 0 :(得分:0)
看到windows_path
类型有点复杂,provider似乎没有可能的方法来预取现有路径的完整列表。因此,您将无法purge
java路径。
只留下一个我可以看到的选项:创建external fact(或纯自定义事实)以检索PATH
中的目录列表。如果您不使用Facter 2,则需要获取分隔的PATH
字符串并在主服务器上处理它。 Facter 2可以将数组交给主人。
如果你将它们放在一个变量中,比如$path_list
,你可以将它们交给一个与你已经使用的类型相似的类型。
filter_path { $path_list: }
define filter_path {
if $name =~ /java/ {
windows_path { $name: ensure => absent, directory => $name }
}
}