如何在 Chef 食谱中执行 curl 命令?
How to execute curl command in Chef recipe?
我有一个 curl 命令,它是 soap 请求,headers 类似于基本身份验证。我需要在 automation.So 的 Chef 食谱中实现这个 curl,每次我执行 chef 脚本时,我都会看到这个 curl 也被执行了。
请告诉我在 chef 脚本中添加 curl 命令的语法。
您可以在厨师食谱中使用 bash 命令
bash 'install_something' do
user 'root'
cwd '/tmp'
code <<-EOH
wget http://www.example.com/tarball.tar.gz
tar -zxf tarball.tar.gz
cd tarball
./configure
make
make install
EOH
end
这里有这个例子:https://docs.chef.io/resource_bash.html。就叫你 curl 命令。
请记住,这不是真正的 Chef 方式。 bash 资源只应在没有其他转义的情况下使用。
您不能使用 http_request 资源执行此操作吗?
类似于:
http_request 'SOAP request' do
url "http://www.example.com/example"
message <xml request>
action :post
end
一个简单的 command
应该可以工作,与此类似。
command "curl -m 5 -i -X POST -d \"payload={}\" http://www.some.place/here"
查阅 curl 的手册页以了解如何添加 http headers。
您还可以使用 bash 资源。例如
bash 'make curl request' do
cwd ::File.dirname(src_filepath)
code <<-EOH
curl -L https://github.com
EOH
end
cwd
是 bash shell 所在的目录 运行。
我有一个 curl 命令,它是 soap 请求,headers 类似于基本身份验证。我需要在 automation.So 的 Chef 食谱中实现这个 curl,每次我执行 chef 脚本时,我都会看到这个 curl 也被执行了。 请告诉我在 chef 脚本中添加 curl 命令的语法。
您可以在厨师食谱中使用 bash 命令
bash 'install_something' do
user 'root'
cwd '/tmp'
code <<-EOH
wget http://www.example.com/tarball.tar.gz
tar -zxf tarball.tar.gz
cd tarball
./configure
make
make install
EOH
end
这里有这个例子:https://docs.chef.io/resource_bash.html。就叫你 curl 命令。 请记住,这不是真正的 Chef 方式。 bash 资源只应在没有其他转义的情况下使用。
您不能使用 http_request 资源执行此操作吗?
类似于:
http_request 'SOAP request' do
url "http://www.example.com/example"
message <xml request>
action :post
end
一个简单的 command
应该可以工作,与此类似。
command "curl -m 5 -i -X POST -d \"payload={}\" http://www.some.place/here"
查阅 curl 的手册页以了解如何添加 http headers。
您还可以使用 bash 资源。例如
bash 'make curl request' do
cwd ::File.dirname(src_filepath)
code <<-EOH
curl -L https://github.com
EOH
end
cwd
是 bash shell 所在的目录 运行。