我有一个curl命令来上传文件并提交表单。
curl --form <file>=@<filename> --form press=<value> [URL]
需要编写一个木偶执行块,如下所示。
ex: exec { "IngestClient $abc_name" :
command => "curl --form file=@$file --form press=Submit http://ipaddress:portno/myapp/abc/"
cwd => "$data/bin",
path => "$data/bin:/usr/bin",
require => [File["$package_file"],Package['curl']],
}
我需要参数化url和文件名以及文件和按钮值。
提前致谢,
答案 0 :(得分:1)
您可以使用参数filename
,url
,abc_name
,data
和package_file
定义自定义类型:
define uploadFile(
$filename = $title,
$url = undef,
$abc_name = undef,
$data = undef,
$package_file = undef
) {
exec { "IngestClient ${abc_name}" :
command => "curl --form file=@${filename} --form press=Submit ${url}"
cwd => "${data}/bin",
path => "${data}/bin:/usr/bin",
require => [ File["${package_file}"], Package['curl'] ]
}
}
然后像这样使用它:
uploadFile { "my-file":
url => "http://ipaddress:portno/myapp/abc",
abc_name => "???",
data => "/foo/bar",
package_file => "???"
}