1

Im using ansible 2.7.5 and a windows 10 host over winRM.

If I execute:

ansible win -I hosts -m win_command -a "PowerShell.exe ipconfig" 

I get an output and it works fine.

But I want to write it inside a playbook and not as an ansible command but I won't get any output so I tried to use stdout but it wont work:

- hosts: win
  gather_facts: no
  tasks:
  - name: PowerShell Command
    win_command: powershell.exe
    register: shell_result
    args: 
      stdin: ipconfig
      -debug: 
         var: shell_result.stdout_lines

Any suggestions how to get the first command working as a playbook?

1 Answer 1

1

Your - debug task isn't indented properly and doesn't have the right spacing. I'm not sure if that's just from posting here or if it's in your original file.

Your call to powershell.exe left out the - parameter which is what tells it to accept input on stdin. So it should be win_command: powershell.exe -.

That said, ipconfig is actually ipconfig.exe so instead of trying to run a shell with win_command just run ipconfig.exe directly:

- hosts: win
  gather_facts: no
  tasks:
  - name: ipconfig
    win_command: ipconfig.exe
    register: shell_result
  - debug: 
      var: shell_result.stdout_lines
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.