Hi there,
I've just started getting into ansible on the Linux side (great software!), and
have spent a little time playing with Windows & Cygwin.
I can report that shell actions are quite reliable - I've been able to
string together policy that execs reg adds conditionally based on a
reg query (using 'register:' & only_if) as well as manipulate
firewalls using netsh. Let me know if you want some examples.
I've put together my first subsantial module named 'winreg' which
manipulates registry entries. Here's some examples:
# before any reg changes are made
$ ssh Administrator@192.168.1.245 \
"reg query \"HKLM\Software\Policies\Microsoft\Windows NT\Terminal Services\" /v fDenyTSConnections"
ERROR: The system was unable to find the specified registry key or value.
# set fDenyTSConnections to 1
$ ansible winsvr -m winreg -a
"keyname='HKLM\Software\Policies\Microsoft\Windows NT\Terminal Services'
valname=fDenyTSConnections
datatype=REG_DWORD
data=0x1
state=present"
winsvr | success >> {
"changed": true
}
$ ssh Administrator@192.168.1.245 \
"reg query \"HKLM\Software\Policies\Microsoft\Windows NT\Terminal Services\" /v fDenyTSConnections"
HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows NT\Terminal Services
fDenyTSConnections REG_DWORD 0x1
# on repeat, changed is false
$ ansible winsvr -m winreg -a
"keyname='HKLM\Software\Policies\Microsoft\Windows NT\Terminal Services'
valname=fDenyTSConnections
datatype=REG_DWORD
data=0x1
state=present"
winsvr | success >> {
"changed": false
}
# set fDenyTSConnections to 0
$ ansible winsvr -m winreg -a
"keyname='HKLM\Software\Policies\Microsoft\Windows NT\Terminal Services'
valname=fDenyTSConnections
datatype=REG_DWORD
data=0x1
state=present"
winsvr | success >> {
"changed": true
}
$ ssh Administrator@192.168.1.245 \
"reg query \"HKLM\Software\Policies\Microsoft\Windows NT\Terminal Services\" /v fDenyTSConnections"
HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows NT\Terminal Services
fDenyTSConnections REG_DWORD 0x0
# absent works too
$ ansible winsvr -m winreg -a
"keyname='HKLM\Software\Policies\Microsoft\Windows NT\Terminal Services'
valname=fDenyTSConnections
state=absent"
winsvr | success >> {
"changed": true
}
$ ssh Administrator@192.168.1.245 \
"reg query \"HKLM\Software\Policies\Microsoft\Windows NT\Terminal Services\" /v fDenyTSConnections"
ERROR: The system was unable to find the specified registry key or value.
I've placed the module on github and would appreciate any feedback.
https://github.com/cgb/ansible_modules/blob/master/windows/winreg
The one strange thing I've seen is the following:
winsvr | FAILED >> {
"cmd": "reg query \"HKLM\\Software\\Policies\\Microsoft\\Windows NT\\Terminal Services\" /v \"fDenyTSConnections\"",
"failed": true,
"msg": "[Errno 11] Resource temporarily unavailable",
"rc": 11
}
It's not clear to me why this is happening - I can run 'reg query'
many times (infinite loop) over one SSH connection, and I can also run
it many times, spawning a new SSH connection each time. But via
ansible, it occasionally spits the resouce temp unavailable message.
Thanks!
Chris Bennett