win_command problems

46 views
Skip to first unread message

norricorp

unread,
Feb 21, 2017, 10:20:57 AM2/21/17
to Ansible Project
Hi,
so if I run on the command line, having used the inventory file to add user/password details under windows:vars
ansible mesh -u user1 -m win_shell -a "dir chdir=C:\Temp"

then I get

mesh | SUCCESS | rc=0 >>

    Directory: C:\Temp

Mode                LastWriteTime         Length Name        

But with a playbook

- name: Run a series of debug tasks to see the value of variables
  hosts: mesh
  user: user1
  tasks:
    - name: list all the files in temp on c drive
      win_command: dir
      args:
         chdir: c:\temp

I get
TASK [list all the files in temp on c drive] ***********************************
fatal: [mesh]: FAILED! => {"changed": false, "cmd": "dir", "failed": true, "msg": "The system cannot find the file specified", "rc": 2}

The win_command module docs show do not show escaping of backslashes or quotes.

What am I doing wrong?

Regards,
John

Matt Davis

unread,
Feb 23, 2017, 12:10:00 PM2/23/17
to Ansible Project
You're using the wrong module. 'dir' isn't a command, it's a shell directive- you need to give that to Powershell or cmd.exe, so you need to use win_shell. win_command is for running an executable.

-Matt

norricorp

unread,
Feb 23, 2017, 1:26:42 PM2/23/17
to Ansible Project
Thanks for this Matt. Yes that makes a lot of sense.


Reply all
Reply to author
Forward
0 new messages