问题描述
我想知道如何将文件从客户端节点传输到远程计算机。我检查了是否有任何资源可用于执行此操作。我发现最接近的东西是 remote_file
,但是它是从远程位置获取文件并将其传输到客户端节点。
I would like to know how to transfer a file from a client node to a remote machine. I have checked whether there any resource available for doing this. The closest thing I found is remote_file
, but it is fetching a file from remote location and transfer it to the client node.
因此,我通过编写bash脚本尝试了另一种选择,该脚本将执行自动scp。但是我无法复制文件,但是Chef-client运行正常,没有显示任何错误。
So I tried another option by writing a bash script which will perform an automated scp. But I cant able to copy the file, but the chef-client was running fine without showing any errors.
这是我用于复制文件的脚本:
Here is my script for copying the file:
#!/usr/bin/expect -f
# connect via scp
spawn scp "/tmp/testfile" [email protected]:/home/chef-ws/fileserver
expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
exp_send "password\r"
}
}
interact
我已将此脚本复制到食谱的
模板
目录为 automatecopy.erb
,然后使用默认值.rb
,我有以下代码
I have copied this script in my cookbook's
templates
directory as automatecopy.erb
and then in default.rb
, I have the following code
template "/tmp/automatecopy" do
source "automatecopy.erb"
mode 0777
end
execute "automatecopy" do
command "/usr/bin/expect /tmp/automatecopy"
timeout 100
action :run
end
在这里,c hef-client成功运行,但是文件未复制到我的工作站计算机上。还有一件事是,当我登录到客户端节点并从那里运行脚本时,脚本便开始工作了。那么,为什么厨师不这样做呢?
Here, the chef-client runs successfully, but the file was not copied to my workstation machine. One more thing is that, when I logged in to my client node and run the script from there, its working. So why chef failing on do so?
请帮我解决这个问题,方法是建议可能出问题的地方,或者有内置的厨师资源可用于将文件从客户端复制到工作站。
Please help me to solve this issue by suggesting what can be wrong or is there any in built chef resource that can be used for copying files from client to workstation.
PS:我的工作站和客户端节点都在运行Ubuntu 12.04。
预先感谢。
P.S: Both my workstation and client node was running Ubuntu 12.04.Thanks in advance.
推荐答案
我已经找到了解决方案。感谢此,它与我的需求类似,因此我发现 sshpass
,而不是期望
。所以我像下面那样更改了脚本,现在厨师很高兴并且可以复制...:)
I have found solution for this.Thanks to this SO post which is similar to my need and there i found the usage of sshpass
instead of expect
. So I altered my script like below and now chef is happy and its copying...:)
使用 sshpass $ c $修改了脚本c>
#!/bin/bash
#Copy file from client's source path to workstation's dest path
sshpass -p <%= @password%> scp -o StrictHostKeyChecking=no <%= @sourcefile%> <%= @user%>@<%= @ip%>:<%= @destinationpath%>
在默认情况下。rb
template "/tmp/automatecopy" do
source "automatecopy.erb"
mode 0777
variables(
:user=> "chef-ws",
:ip=> "10.232.110.113",
:sourcefile=> "/tmp/outfile",
:destinationpath => "/home/chef-ws/fileserver",
:password=> "pass"
)
end
这篇关于将文件从Chef客户端节点复制到工作站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!