salt icon indicating copy to clipboard operation
salt copied to clipboard

running cmd.script removes source file in file_roots of standalone windows minion (v17.2)

Open emmellee opened this issue 12 years ago • 14 comments

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

emmellee avatar Dec 04 '13 20:12 emmellee

Wow, that's no good! Thanks for the report!

basepi avatar Dec 04 '13 20:12 basepi

@UtahDave Ping

basepi avatar Dec 04 '13 20:12 basepi

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.

emmellee avatar Dec 10 '13 17:12 emmellee

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') }}

emmellee avatar Dec 10 '13 18:12 emmellee

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.

basepi avatar Dec 10 '13 21:12 basepi

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.

emmellee avatar Dec 10 '13 22:12 emmellee

Does the cmd.run fail if you give it a real path to the script? Instead of a salt:// path?

basepi avatar Dec 10 '13 23:12 basepi

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.

emmellee avatar Dec 12 '13 15:12 emmellee

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.

emmellee avatar Dec 12 '13 17:12 emmellee

Ah, yes, that does make more sense!

Did that resolve all your issues? Can this be closed?

basepi avatar Dec 12 '13 22:12 basepi

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.

emmellee avatar Dec 12 '13 23:12 emmellee

We should probably still work to get this working on masterless. It should not be deleting your original file.

basepi avatar Dec 12 '13 23:12 basepi

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.

emmellee avatar Dec 13 '13 14:12 emmellee

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/

UtahDave avatar Dec 13 '13 17:12 UtahDave