Ansible reports "ok" for a script if the return code is 0. PowerShell scripts don't normally return a nonzero exit code even if there is an error. You'll need to use a trap construct or try/catch block to exit with a different code and display an error message, e.g.:
https://github.com/ansible/ansible/blob/devel/test/integration/roles/test_win_script/files/test_script_with_errors.ps1 The groups and groups_action options weren't added to the win_user module until 1.9. If you run ansible with the -v option you'll see the stdout/stderr from your script, and can turn on additional debugging output using additional v's (up to -vvvvv). On Wed, Apr 15, 2015 at 10:34 PM, Michael Legleux <[email protected]> wrote: > *Ansible 1.8.4 on ubuntu 12.04 to connect to windows 8.1* guest vm using > literally the exact same windows module examples from the ansible > documentation. > ansible -m win_ping and -m setup work great. > 2 Problems standing in my way > 1. I am trying to mount a network drive using ansible. The play is simply: > > - name: 'Mount drive to T' > hosts: windows > tasks: > script: mount_drive.ps1 > > mount_drive.ps1 is simply > New-PSDrive -Name T -PSProvider FileSystem -Root > \\some_mountable_drive\dir -Persist > > When this is executed, ansible happily reports the play recap it was "ok" > which is a lie. > > I know that this works because I have run the command while logged in on > the windows guest as the user in question and the drive is mounted > immediately. > *I also used the win_rm python module to execute this command with success*. > I define "success" a little looser here because the drive doesn't appear > immediately, but after logout/login but I chalk that up to windows bs. > > If the command works (almost) perfectly with the python win_rm module. I > can't figure out what am i doing wrong with the ansible play. > > Problem 2: > - name: Add user > hosts: windows > tasks: > - name: Add newuser > win_user: > name: anewuser > password: "shhhh" > groups_action: replace # with or without this matters not > groups: ["Users","Administrators"] > > The user is created fine via inspection with lsusrmgr, however the user is > not added to those groups > > please point me in the right direction. Also some way to get meaningful > output from the remote commands would be nice. win_rm captures the stdout > and err from powershell commands, which is how I debugged the win_rm python > module to mount the drive just fine. > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/6075ae5c-cf3f-4db0-aa2e-cdad3d04cd90%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/6075ae5c-cf3f-4db0-aa2e-cdad3d04cd90%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAH%2BKTJ4vW5GVu1WgX7cC1ZbSm6c9gWCt-kb0W0KL6bNP%2BBomgQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
