file.copy not working on windows minion (v17.2)
In the following example the source file exists. However, file.copy reports the source file does not exist while file.managed sees the source file and copies it. Because I do not want the target file to be overwritten if it exists, I need to use file.copy not file.managed.
D:\\teamcity-buildagent\conf\buildAgent.properties:
file:
- copy
- source: salt://templates/buildAgent.properties
- require:
- cmd: teamcity-unzip-buildagent
results in
[INFO ] Executing state file.copy for D:\\teamcity-buildagent\conf\buildAgent.properties
[ERROR ] Source file "salt://templates/buildAgent.properties" is not present
[ERROR ] Unable to write to "state.sls" cache file c:\salt\var\cache\salt\minion\sls.p
Now, if I replace "- copy" with "- managed" in the state file, the file is copied from source.
We do plan to fix this bug, but just FYI, as a workaround, you can actually do - replace: False on a file.managed state to have it not replace the target file.
Thinking there might be a difference in file format for file.copy vs file.managed as there is with cmd.run and cmd.script, I tried the following and it worked.
D:\\teamcity-buildagent\conf\buildAgent.properties:
file:
- copy
- source: D://srv/salt/file_roots/templates/buildAgent.properties
- require:
- cmd: teamcity-unzip-buildagent
Not knowing when I'm supposed to use which format, it's all just trial and error with me... Don't know if this difference should exist, so I'll report it even though I found a workaround and you can determine whether this is a bug or not.
ah, thank you. I did not know about the file.managed -replace false thing.
@emmellee , have you tried this?
salt 'minionName' file.stats D://srv/salt/file_roots/templates/buildAgent.properties
There is a documented idiosyncracy in Python's os.path.exists() function detailed below:
On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.
Stats gives me some information but many of the file functions don't seem to be available for windows.
C:\salt>salt-call file.stats D://srv/salt/file_roots/templates/buildAgent.proper
ties
[INFO ] Executing command 'Powershell D://srv/salt/file_roots/scripts/get-OOB
IP.ps1' in directory 'C:\\Users\\xxxx.xxxx'
[INFO ] Executing command 'hostname' in directory 'C:\\Users\\xxxx.xxxx
'
←[0;36mlocal←[0m:
←[0;36m----------←[0m
←[0;36matime←[0m:
←[1;33m1386944792.65←[0m
←[0;36mctime←[0m:
←[1;33m1386944792.65←[0m
←[0;36mgid←[0m:
←[1;33m0←[0m
←[0;36mgroup←[0m:
←[1;33m0←[0m
←[0;36minode←[0m:
←[1;33m0←[0m
←[0;36mmode←[0m:
←[0;32m0666←[0m
←[0;36mmtime←[0m:
←[1;33m1387227441.99←[0m
←[0;36msize←[0m:
←[1;33m195←[0m
←[0;36msum←[0m:
←[0;32m58a2464645c7e010ffeb7d37e8a65bac←[0m
←[0;36mtarget←[0m:
←[0;32mD:\srv\salt\file_roots\templates\buildAgent.properties←[0m
←[0;36mtype←[0m:
←[0;32mfile←[0m
←[0;36muid←[0m:
←[1;33m0←[0m
←[0;36muser←[0m:
←[1;33m0←[0m
C:\salt>salt-call file.get_attributes D://srv/salt/file_roots/templates/buildAge
nt.properties
[INFO ] Executing command 'Powershell D://srv/salt/file_roots/scripts/get-OOB
IP.ps1' in directory 'C:\\Users\\xxx.xxxxx'
[INFO ] Executing command 'hostname' in directory 'C:\\Users\\xxxx.xxxxx
'
Function file.get_attributes is not available
Yes, many of these routines must be rewritten for Windows support, and though we have the main ones, many of the less-popular functions have not been written with windows support.
I just confirmed this bug report
Working on a fix
This bug actually exists on all platforms. Just tested on Ubuntu.
OK, upon further investigation I realized that file.copy doesn't accept a "source" argument. file.copy is intended for copying a file from one location to another within the file system of the same minion. @basepi is correct in that you should use the "- replace: False" option of file.managed.
@emmellee I'm going to close this issue since I believe this function is working as intended. Please feel free to comment here or reopen this issue if you disagree. Thanks!
@UtahDave Can we have this information from your very last comment here added to the documentation for file.copy? The current documentation sounds a little too similar to file.managed and it's not clear that file.copy is intended to operate solely on the minion itself.
From http://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html#salt.states.file.copy:
If the source file exists on the system, copy it to the named file.
That seems fairly clear to me, though perhaps it is easy to miss. Would changing "system" to "minion" help? I'm not sure how to word this better.