Copy directory from chef-workstation to chef-node

Hi
I am trying to copy Directory from chef-workstation to chef-node on window environment.
I am using below recipe

remote_directory 'C:\chef-repo\recipes\destination' do
  source 'C:\chef-repo\recipes\source'
  action :create
end

But It is not working.

The reason that doesn't work is because if you specify a remote file like that to like c:\ or /tmp chef thinks you are talking about the local file system on the node itself, it wont copy files from your workstation to the node like that.

What you could do it create a share on your workstation and then put the file(s) you want to access in there and reference that in your cookbook like this there are more examples in the remote_portion of the chef docs search for UNC.

remote_file "E:/domain_test.txt"  do
  source  "\\\\myserver\\myshare\\mydirectory\\myfile.txt"
  remote_domain "domain"
  remote_user "username"
  remote_password "password"
end

Hi

Shared "ShareFolder with x-user.
Now write below recipe to copy hello.txt file:

remote_file 'C:/test/hello.txt' do
  source  "\\\CHEF-SERVER-Machine\\ShareFolder\\hello.txt"
  remote_domain "x-domain"
  remote_user "x-user"
  remote_password "x-password"
  action :create
end

Getting error:

[2018-08-31T01:31:18-07:00] ERROR: Remote chef-client error follows:
[2018-08-31T01:31:18-07:00] ERROR: Errno::EINVAL: remote_file[C:/test/hello.txt] (Remote_Directory::default line 8) had an error: Errno::EINVAL: Invalid argument @ rb_sysopen - \\CHEF-SERVER-Machine\ShareFolder\hello.txt

It looks like you are missing a \ before your source patch there should be 4 of them \\.

I would also check that the user account you are using can access the share.

Hi

By mistake I forgot to add one \ in the blog. But I am using 4 times .
I am able to access share file through window url by using same domain, username and password.
But no through chef. Facing same error.

Thanks
Deepak

Oh ok I just wanted to make sure you had all 4.

Are you on a active directory domain? You also may need to make a change to your workstation firewall to allow the connections you would need to allow connections over port 445.

Hi

I turn off the Firewall of chef-workstation, still same error. Invalid Argument

[2018-08-31T05:57:39-07:00] ERROR: Remote chef-client error follows:
[2018-08-31T05:57:39-07:00] ERROR: Errno::EINVAL: remote_file[C:/chef/hello.txt] (Remote_Directory::default line 8) had an error: Errno::EINVAL: Invalid argument @ rb_sysopen - \\CHEF-SERVER-Machine\ShareFolder\hello.txt

Is your chef workstation the same as chef-server-machine?

yes

Just to inform you, I am directly communicating between chef-workstation and chef-node.
I have no chef-server.

I got a windows vagrant box and tried this out.

I created a local share and gave my user account implicit full access to the share

under sharing I clicked advanced sharing checked the box, gave the share a name of share$, then I clicked permissions, added my user account and gave it full access. then clicked ok.

I then made a quick cookbook with a recipe as follows.

directory 'c:/test' do
action :create
end

remote_file 'c:/test/test.txt' do
source '\\laptop.company.com\share$\test.txt'
remote_domain 'company.com'
remote_user 'larryc'
remote_password 'Hunter2'
action :create
end

and it worked as expected

Recipe: filecopy::default
* directory[c:/test] action create (up to date)
* remote_file[c:/test/test.txt] action create
- create new file c:/test/test.txt
- update content in file c:/test/test.txt from none to e3b0c4
(no diff)

You might want to check that your share has the proper permissions.

Thanks Larryc

I got the mistake. I was not using domain in the source path.
Below script is working file.

remote_file 'C:/test/hello.txt' do
  source  "\\\CHEF-SERVER-Machine.x-domain\\ShareFolder\\hello.txt"
  remote_domain "x-domain"
  remote_user "x-user"
  remote_password "x-password"
  action :create
end

Cool glad I could be of help.