Curl 通过puppet 3.7.4中的环境变量动态设置卷曲路径返回;找不到命令''&引用;
我们的一些实例运行在较旧的操作系统上,这些操作系统的curl命令位置与其他操作系统不同,这是由于“curl:command not found”错误导致这些节点上的puppet运行失败 然后我们尝试设置Curl 通过puppet 3.7.4中的环境变量动态设置卷曲路径返回;找不到命令''&引用;,curl,environment-variables,exec,puppet,redhat,Curl,Environment Variables,Exec,Puppet,Redhat,我们的一些实例运行在较旧的操作系统上,这些操作系统的curl命令位置与其他操作系统不同,这是由于“curl:command not found”错误导致这些节点上的puppet运行失败 然后我们尝试设置命令=>导出$curl\u path=$(哪个curl)&&$curl\u path-sS-o${service\u to\u install}https://service_to_install.parent.com/service_to_install ||rm-f${service\u to
命令
=>导出$curl\u path=$(哪个curl)&&$curl\u path-sS-o${service\u to\u install}https://service_to_install.parent.com/service_to_install ||rm-f${service\u to\u install}“
但是由于export:command not found
我发现另一篇帖子建议使用environment=>
设置curl\u path变量,如下所示:
$service_to_install = '/root/service_to_install'
exec { 'service_to_install_placeholder':
command => "/bin/echo Unauthorized > ${service_to_install)}",
creates => $service_to_install,
}
# Download the installer.
exec { 'fetch_service_to_install' :
environment => ["curl_path=$(which curl)"],
command => "$curl_path -sS -o ${service_to_install} https://service_to_install.parent.com/service_to_install || rm -f ${service_to_install}",
path => [ '/sbin', '/bin', '/usr/sbin', '/usr/bin' ],
timeout => 600,
onlyif => "/bin/grep -q Unauthorized ${service_to_install}",
}
# then we run the installer
exec { 'agent_install' :
command => "bash ${service_to_install} ",
path => [ '/sbin', '/bin', '/usr/sbin', '/usr/bin' ],
timeout => 600,
require => Exec['fetch_service_to_install'],
}
但这会导致/Stage[main]/Jumpcloud\u login/Exec[fetch\u service\u to\u install]/returns
找不到命令“”
如何在此处使用which curl命令动态设置curl
如果有问题的话,我们看到错误的系统是Amazon Linux AMI release 2018.03 RedHat。这似乎是Hiera在
facts.os.name
和facts.os.release.major
(及类似版本)上匹配的完美用例。您可以想象您的顶级Hiera.yaml
看起来像:
curl_path = lookup('my_module::curl_path', String)
exec { 'fetch_service_to_install' :
command => "${curl_path} -sS -o ${service_to_install} https://service_to_install.parent.com/service_to_install || rm -f ${service_to_install}",
path => [ '/sbin', '/bin', '/usr/sbin', '/usr/bin' ],
timeout => 600,
onlyif => "/bin/grep -q Unauthorized ${service_to_install}",
}
版本:5
默认值:
数据目录:数据
数据\u散列:yaml\u数据
等级制度:
-名称:“操作系统特定数据”
路径:'os/%{facts.os.name}-%{facts.os.release.major}.yaml'
-名称:“公共数据”
路径:“common.yaml”
然后在那里使用一个名为my\u module::curl\u path
的变量,该变量可能在common.yaml
中默认为/usr/bin/curl
,否则会被旧的/不同的机器覆盖
此时,您的代码将类似于:
curl_path = lookup('my_module::curl_path', String)
exec { 'fetch_service_to_install' :
command => "${curl_path} -sS -o ${service_to_install} https://service_to_install.parent.com/service_to_install || rm -f ${service_to_install}",
path => [ '/sbin', '/bin', '/usr/sbin', '/usr/bin' ],
timeout => 600,
onlyif => "/bin/grep -q Unauthorized ${service_to_install}",
}
(可能最好将其作为清单/模块参数,这样就不需要
lookup()
。这似乎是在facts.os.name
和facts.os.release.major
上进行Hiera匹配的完美用例。您可以想象您的顶级Hiera.yaml
看起来像:
curl_path = lookup('my_module::curl_path', String)
exec { 'fetch_service_to_install' :
command => "${curl_path} -sS -o ${service_to_install} https://service_to_install.parent.com/service_to_install || rm -f ${service_to_install}",
path => [ '/sbin', '/bin', '/usr/sbin', '/usr/bin' ],
timeout => 600,
onlyif => "/bin/grep -q Unauthorized ${service_to_install}",
}
版本:5
默认值:
数据目录:数据
数据\u散列:yaml\u数据
等级制度:
-名称:“操作系统特定数据”
路径:'os/%{facts.os.name}-%{facts.os.release.major}.yaml'
-名称:“公共数据”
路径:“common.yaml”
然后在那里使用一个名为my\u module::curl\u path
的变量,该变量可能在common.yaml
中默认为/usr/bin/curl
,否则会被旧的/不同的机器覆盖
此时,您的代码将类似于:
curl_path = lookup('my_module::curl_path', String)
exec { 'fetch_service_to_install' :
command => "${curl_path} -sS -o ${service_to_install} https://service_to_install.parent.com/service_to_install || rm -f ${service_to_install}",
path => [ '/sbin', '/bin', '/usr/sbin', '/usr/bin' ],
timeout => 600,
onlyif => "/bin/grep -q Unauthorized ${service_to_install}",
}
(最好将其设置为清单/模块参数,这样就不需要
lookup()
).错误消息意味着哪个curl
返回空字符串。是的,这很明显,但是当我进入主机时,哪个curl
返回/usr/bin/curl
因为哪个不是命令,你可以尝试sh-c'which curl'
。我将该行更改为环境=>[“curl\u路径”=$(sh-c'which curl')”,
导致相同错误/Stage[main]/Jumpcloud\u login/Exec[fetch\u kickstart]/返回
将notrun更改为0失败:找不到命令“”
错误消息暗示哪个curl
返回空字符串。是的,这很明显,但当我进入主机时,哪个curl
返回/usr/bin/curl
因为哪个
不是命令,您可以尝试sh-c'哪个curl'
。我将该行更改为environment=>[“curl\u path=$(sh-c'which curl')”],
这导致了相同的错误/Stage[main]/Jumpcloud\u login/Exec[fetch\u kickstart]/返回
从notrun更改为0失败:找不到命令“”
我应该提到我忘记了您正在使用Puppet 3.7,它需要与上面不同的设置。我应该提到我忘记了您正在使用Puppet 3.7,它需要与上面不同的设置。