Run a .json file via command line

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”’

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

Thank you sir, the last command worked, though win_shell did not.
Follow up: what is the switch to run cmd.exe AS ADMINISTRATOR?

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