running cmd.script removes source file in file_roots of standalone windows minion (v17.2)
I tried this is my state file:
D:\\tomcats\tomcat-jenkins\webapps:
file.directory:
- makedirs: True
cmd.script:
- name: salt://scripts/set-webappsACL.ps1
It ran successfully, that is, it set the ACL on the folder as intended, but cmd.script removed my file /scripts/set-webappsACL.ps1 after the run. I thought maybe it was being overwritten because it needed a working directory, so I modified to use templates, like this:
D:\\tomcats\tomcat-jenkins\webapps:
file.directory:
- makedirs: True
cmd.script:
- name: set-webappsACL.ps1
- cwd: D:\temp
- source: salt://templates/setCIacls.ps1
- context:
DIR: D:\tomcats\tomcat-jenkins\webapps
- require:
- file: D:\\temp
But, still, cmd.script removed (overwrote?) my file /templates/setCIacles.ps1
Wow, that's no good! Thanks for the report!
@UtahDave Ping
I'm understanding this better. I had the notion that cmd.run ran a command and cmd.script ran a script; but now I see that cmd.script is more about "downloading" and I should be able to run my scripts with cmd.run. I am finding some success in that (cmd.run), so my issue of not being able to use cmd.script on a masterless windows minion is not a big issue.
But what remains an issue is that I am unable to set a variable using cmd.run within pillars.
While this works from the command line:
salt-call cmd.run 'D:\srv\salt\file_roots\scripts/get-OOBIP.ps1' shell='powershell'
Attempting to set a variable within pillars like this does not work:
OIP: {{ salt-call['cmd.run']('D:\srv\salt\file_roots\scripts\get-OOBIP.ps1', shell='powershell') }}
or
OIP: {{ salt-call['cmd.run']('salt://scripts/get-OOBIP.ps1', shell='powershell') }}
The above pillar attempts result in this error:
[CRITICAL] Pillar render error: Rendering SLS 'myvars' failed, render error:
Undefined jinja variable; line 378 in template
So I'm unable to use salt-call within pillars; yet as a masterless minion, executing salt (vs salt-call) within pillars will delete my script:
OIP: {{ salt['cmd.run']('salt://scripts/get-OOBIP.ps1', shell='powershell') }}
salt-call is not a valid variable in templates. When you're executing the last example, you need to use cmd.script instead of cmd.run -- cmd.run doesn't support salt:// I don't think.
But unfortunately cmd.script will not run properly in my environment - it continually deletes my script. I think that's because I'm masterless. Either way, I'm out of luck because pillars won't allow salt-call and cmd.script won't run on a windows masterless minion.
Does the cmd.run fail if you give it a real path to the script? Instead of a salt:// path?
Yes, I did try that but I don't recall the exact failure - though I believe it deleted file also. I will rerun and cut/paste the response.
Ah, I had used cmd.run with real paths within pillars and had a rendering issue with this line:
OIP: {{ salt['cmd.run']('D:\srv\salt\file_roots\scripts\get-OOBIP.ps1', shell='powershell') }}
But I've since retried it with what seems to be the right format and achieved success with this line:
OIP: {{ salt['cmd.run']('D://srv/salt/file_roots/scripts/get-OOBIP.ps1', shell='powershell') }}
Yay! Things are looking up. Thank you.
Ah, yes, that does make more sense!
Did that resolve all your issues? Can this be closed?
As long as cmd.script is not intended to ever work for a masterless windows environment, then yes. Cmd.run does appear to be working for me. I can understand why cmd.script might not be intended to work since it has a "downloading purpose". Thanks for your help.
We should probably still work to get this working on masterless. It should not be deleting your original file.
I did think of a reason why I would want this. Even though I have a masterless windows minion environment now, I hope that that won't always be the case. And if cmd.script would work, "salt://" could be configurable in any environment and I would not have to change my code when I moved to a master'd environment. As it stands right now, in each instance where I'm having to hardcode the physical path, I will have to change that if/when I move to a master'd environment.
Yes, let's get this working so that cmd.script will work with salt://
On Fri, Dec 13, 2013 at 7:57 AM, emmellee [email protected] wrote:
I did think of a reason why I would want this. Even though I have a masterless windows minion environment now, I hope that that won't always be the case. And if cmd.script would work, "salt://" could be configurable in any environment and I would not have to change my code when I moved to a master'd environment. As it stands right now, in each instance where I'm having to hardcode the physical path, I will have to change that if/when I move to a master'd environment.
— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/9032#issuecomment-30514856 .
Dave Boucha | Sr. Engineer
Join us at SaltConf, Jan. 28-30, 2014 in Salt Lake City. www.saltconf.com
5272 South College Drive, Suite 301 | Murray, UT 84123 office 801-305-3563 [email protected] | www.saltstack.com http://saltstack.com/