Copy file from chef client node to workstation

HRM

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.

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

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

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.

P.S: Both my workstation and client node was running Ubuntu 12.04. Thanks in advance.

HRM

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...:)

Modified script using sshpass

#!/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%>

And in default.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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error while copying war file from workstation to client node?`

From Dev

Chef: Running chef-client during knife upload / knife role from file

From Dev

How to script changing the node name of a client in chef from the client without knife

From Dev

install software on remote server from the workstation using chef

From Dev

Chef workstation error

From Dev

Chef: Upgrade chef-client version during knife boostrap on node

From Dev

chef-client node name must be identical to client name?

From Dev

how to javascript file copy from server to client pc by script

From Dev

Chef Powershell Run from File

From Dev

Copy workstation AD groups from one computer to another while ignoring existing workstation groups

From Dev

Use PowerShell to copy files from workstation to server, preserving the directory structure

From Dev

copy a user directory from one to another workstation on a same domain

From Dev

Use PowerShell to copy files from workstation to server, preserving the directory structure

From Dev

Update node tags from Chef LWRP

From Dev

How to remove the recipes from the Node for Chef

From Dev

Getting node information from chef recipe

From Dev

How to remove the recipes from the Node for Chef

From Dev

Chef client hanging on npm install at node-gyp rebuild

From Dev

Chef client installed on a image, want to have it create its own node

From Dev

Chef client re-register breaks ability to save node data back to chef server

From Dev

How to add chef-client recipe on new born client node (after client register)

From Dev

Java - copy/paste file from client to server getting error - UTF-8 encoding problem opening file

From Dev

Copying a file from a server to client using Libssh: issues with assigning file copy destination path

From Dev

Access a Chef data bag from an attributes file

From Dev

Get one file from git using chef

From Dev

Generate then read contents from a file chef

From Dev

Chef: append to an exsting file from an "erb" template

From Dev

How to pass attributes in chef-client without JSON file?

From Dev

XSLT- Copy node from other XML file, based on matching node value

Related Related

  1. 1

    Error while copying war file from workstation to client node?`

  2. 2

    Chef: Running chef-client during knife upload / knife role from file

  3. 3

    How to script changing the node name of a client in chef from the client without knife

  4. 4

    install software on remote server from the workstation using chef

  5. 5

    Chef workstation error

  6. 6

    Chef: Upgrade chef-client version during knife boostrap on node

  7. 7

    chef-client node name must be identical to client name?

  8. 8

    how to javascript file copy from server to client pc by script

  9. 9

    Chef Powershell Run from File

  10. 10

    Copy workstation AD groups from one computer to another while ignoring existing workstation groups

  11. 11

    Use PowerShell to copy files from workstation to server, preserving the directory structure

  12. 12

    copy a user directory from one to another workstation on a same domain

  13. 13

    Use PowerShell to copy files from workstation to server, preserving the directory structure

  14. 14

    Update node tags from Chef LWRP

  15. 15

    How to remove the recipes from the Node for Chef

  16. 16

    Getting node information from chef recipe

  17. 17

    How to remove the recipes from the Node for Chef

  18. 18

    Chef client hanging on npm install at node-gyp rebuild

  19. 19

    Chef client installed on a image, want to have it create its own node

  20. 20

    Chef client re-register breaks ability to save node data back to chef server

  21. 21

    How to add chef-client recipe on new born client node (after client register)

  22. 22

    Java - copy/paste file from client to server getting error - UTF-8 encoding problem opening file

  23. 23

    Copying a file from a server to client using Libssh: issues with assigning file copy destination path

  24. 24

    Access a Chef data bag from an attributes file

  25. 25

    Get one file from git using chef

  26. 26

    Generate then read contents from a file chef

  27. 27

    Chef: append to an exsting file from an "erb" template

  28. 28

    How to pass attributes in chef-client without JSON file?

  29. 29

    XSLT- Copy node from other XML file, based on matching node value

HotTag

Archive