Ansible windows 8.1 management...

79 views
Skip to first unread message

Michael Legleux

unread,
Apr 16, 2015, 8:23:25 AM4/16/15
to ansible...@googlegroups.com
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.

Chris Church

unread,
Apr 16, 2015, 2:14:42 PM4/16/15
to ansible...@googlegroups.com
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.:


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).


--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6075ae5c-cf3f-4db0-aa2e-cdad3d04cd90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages