Run a .json file via command line

244 views
Skip to first unread message

lpesc...@google.com

unread,
Dec 21, 2017, 5:18:30 PM12/21/17
to Ansible Project
Hi, I want to start a json (gcloud) file via command line (win 10 pc) in ansible. 

What I am trying now is:

name: run command

  win_command: C:\Windows\System32\cmd.exe gcloud auth activate-service-account --key-file=C:\Users\user\Desktop\foo.json


All that happens is the command prompt opens. 

When I manually paste "gcloud auth activate-service-account --key-file=C:\Users\user\Desktop\foo.json" into a command prompt it works. 


Thus I just think the syntax is incorrect. Any idea on the proper syntax to run something through cmd?

I have also tried 

win_command: 'C:\Windows\System32\cmd.exe "gcloud auth activate-service-account --key-file=C:\Users\user\Desktop\foo.json"'

Jordan Borean

unread,
Dec 21, 2017, 7:24:08 PM12/21/17
to Ansible Project
You can try just running the gcloud executable by itself to make things simpler like so

- win_command: gcloud auth activate-service-account --key-file=C:\Users\user\Desktop\foo.json

This should work unless that relies on any shell ism's which are not available in win_command. Otherwise you have 2 other options if you really need to run it under command prompt

- name: run it under win_shell and specify it to run under the cmd shell
  win_shell
: gcloud auth activate-service-account --key-file=C:\Users\user\Desktop\foo.json
  args
:
    executable
: cmd.exe

- name: run it under win_command by creating a new cmd shell and executing the command
  win_command
: cmd.exe /c gcloud auth activate-service-account --key-file=C:\Users\user\Desktop\foo.json


The last example is close to what you were trying to do but to run a command in cmd you must pass the /c argument telling it what command to actually run.

Thanks

Jordan

Larry Pescatore

unread,
Dec 22, 2017, 5:14:24 PM12/22/17
to ansible...@googlegroups.com
Thank you sir, the last command worked, though win_shell did not. 
Follow up: what is the switch to run cmd.exe AS ADMINISTRATOR?

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/Nx0WjMGtNow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/800ff38e-54b9-42ff-9bba-4fbb5006bc2d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thank you, 
Larry Pescatore
Lab Engineer, ERG Inc. @ Google

Jordan Borean

unread,
Dec 22, 2017, 6:07:56 PM12/22/17
to Ansible Project
A WinRM command always runs with the highest privileges possible, so under and admin it should run as an admin. You can check it out by running ‘whoami /groups’ in win_command, the mandatory label at the bottom tells you what level of privileges you are running with.

- medium is a standard user without admin privileges
- high is with admin privileges
- system is running under a well know service account and is similar to high
Reply all
Reply to author
Forward
0 new messages