Ansible Management windows2008

Source: Internet
Author: User

0x00. To automate the management of Windows servers, test Ansbile manage windows

Test tools, Environment: Ubuntu 14.04 lts,windows SP2, python2.7, Ipython, ansible1.7


0x01. Initial configuration of WinRM on Windows Server

A. Upgrading PowerShell

Https://github.com/cchurch/ansible/blob/devel/examples/scripts/upgrade_to_ps3.ps1

B. Configuring WinRM

Https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1


Installing the PYWINRM on the Ansible main control machine


Pip Install HTTP://GITHUB.COM/DIYAN/PYWINRM/ARCHIVE/MASTER.ZIP#EGG=PYWINRM


Test Ansible Module

A. Setting the host file for Ansible


Cat/etc/ansible/hosts

[Test-win]

Test-win ansible_ssh_host=10.8.200.20 ansible_ssh_user=administrator ansible_ssh_pass= "Testwindows" Ansible_ssh_ port=5986 ANSIBLE_CONNECTION=WINRM


B. Test the Win_ping module

[email protected]:~$ ansible test-win -m win_ping -vvvv<10.8.200.20>  establish winrm connection for user: administrator on port 5986  to 10.8.200.20<10.8.200.20> winrm connect: transport=plaintext endpoint=https:/ /10.8.200.20:5986/wsmantest-win | failed => traceback  (Most recent call  last):  file  "/usr/local/python/lib/python2.7/site-packages/ansible/runner/__init__.py",  line 561, in _executor    exec_rc = self._executor_internal (Host, new_stdin)   File  "/usr/local/python/lib/python2.7/site-packages/ansible/runner/__ init__.py ",  line 666, in _executor_internal    return self._ Executor_internal_inner (host, self.module_name, self.module_args, inject, port,  Complex_args=complex_args)   File  "/usr/local/python/lib/python2.7/site-packages/ansible/runner/__init__.py",  line  837, in _executor_internal_inner    conn =  Self.connector.connect (Actual_host, actual_port, actual_user, actual_pass, actual_ Transport, actual_private_key_file)   File  "/usr/local/python/lib/python2.7/site-packages/ ansible/runner/connection.py ",  line 34, in connect    self.active  = conn.connect ()   File  "/usr/local/python/lib/python2.7/site-packages/ansible/runner /connection_plugins/winrm.py ",  line 132, in connect    self.protocol  = self._winrm_connect ()   File  "/usr/local/python/lib/python2.7/site-packages/ansible /runner/connection_plugins/winrm.py ", line 90, in _winrm_connect     Err_msg = str (Exc.args[0]) Indexerror:&nbsP;tuple index out of range 


C. Test whether the PYWINRM is working properly

In [1]: import winrm in [2]: s = winrm. Session (' Https://10.8.200.20:5986/wsman ', auth= (' Administrator ', ' testwindows '))  in [3]: r =  s.run_cmd (' ipconfig ')  In [4]: r.std_outOut[4]:  ' \r\nwindows ip  configuration\r\n\r\n\r\nethernet adapter \xb1\xbe\xb5\xd8\xc1\xac\xbd\xd3:\r\n\r\n    Connection-specific DNS Suffix  . : \r\n   Link-local  ipv6 address . . . . . : fe80::3dcc:e005:1039:b1%10\r\n    IPv4 Address. . . . . . . . . . . :  10.8.200.20\r\n   subnet mask . . . . . . . .  . . . : 255.255.255.0\r\n   default gateway . . .  . . . . . . : 10.8.200.254\R\n\r\ntunnel adapter \xb1\xbe\xb5\xd8\xc1\xac\xbd\xd3*:\r\n\r\n   media state  . . . . . . . . . . . : Media  Disconnected\r\n   connection-specific dns suffix  . : \r\n\r\ Ntunnel adapter \xb1\xbe\xb5\xd8\xc1\xac\xbd\xd3* 8:\r\n\r\n   media state  . . . . . . . . . . . : Media  Disconnected\r\n   connection-specific dns suffix  . : \r\n '




Found Pywinrm normal work, but ansilbe not working properly, there may be pywinrm problems

sudo pip install Https://github.com/diyan/pywinrm/archive/df049454a9309280866e0156805ccda12d71c93a.zip


Test again

[email protected]:~$ ansible test-win -m win_ping -vvvv -- ask-vault-passvault password:<10.8.200.20> establish winrm connection for  User: administrator on port 5986 to 10.8.200.20<10.8.200.20> winrm  CONNECT: transport=plaintext endpoint=https://10.8.200.20:5986/wsman<10.8.200.20>  remote_module win_ping<10.8.200.20> exec  (New-item -type directory -path   $env:temp -name  "ansible-tmp-1411890350.69-117079676086926"). fullname | write-host -separator  ';<10.8.200.20> winrm exec  ' PowerShell '  ['-noprofile ',  '-noninteractive ',  '-encodedcommand ',  ' Kaboaguadwataekadablag0aiaatafqaeqbwaguaiabeagkacgblagmadabvahiaeqagac0auabhahqaaaagacqazqbuahyaogb0aguabqbwacaalqboageab Qblacaaigbhag4acwbpagiabablac0adabtahaalqaxadqamqaxadgaoqawadmanqawac4anga5ac0amqaxadcAmaa3adkanga3adyamaa4adyaoqayadyaigapac4argb1agwababoageabqblacaafaagafcacgbpahqazqataegabwbzahqaiaatafmazqbwageacgbhahqa Bwbyacaajwanadsa ']<10.8.200.20> winrm result <response code 0, out   "C:\Users\Administrat", err  "" ><10.8.200.20> put /tmp/tmp6kqnkv to  C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1411890350.69-117079676086926\\win_ping< 10.8.200.20> winrm put /tmp/tmp6kqnkv to c:\users\administrator\appdata\local\temp \ansible-tmp-1411890350.69-117079676086926\\win_ping.ps1  (offset=0 size=2030) <10.8.200.20>  winrm put /tmp/tmp6kqnkv to c:\users\administrator\appdata\local\temp\ ansible-tmp-1411890350.69-117079676086926\\win_ping.ps1  (offset=2030 size=2030) <10.8.200.20>  winrm put /tmp/tmp6kqnkv to c:\users\administrator\appdata\local\temp\ Ansible-tmp-1411890350.69-117079676086926\\win_ping.ps1  (offset=4060 size=1425) <10.8.200.20> put /tmp/tmpmctn8u to c:\users \administrator\appdata\local\temp\ansible-tmp-1411890350.69-117079676086926\\arguments<10.8.200.20>  winrm put /tmp/tmpmctn8u to c:\users\administrator\appdata\local\temp\ ansible-tmp-1411890350.69-117079676086926\\arguments  (offset=0 size=2) <10.8.200.20> EXEC  PowerShell -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -File  "C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1411890350.69-117079676086926\\win_ping.ps1"   "c \ Users\administrator\appdata\local\temp\ansible-tmp-1411890350.69-117079676086926\\arguments ";  Remove-Item   "C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1411890350.69-117079676086926\"  -Force  -recurse;<10.8.200.20> winrm exec  ' PowerShell '  ['-noprofile ',  '-NonInteractive ' ,  '-encodedcommand ', ' Uabvahcazqbyafmaaablagwabaagac0atgbvafaacgbvagyaaqbsaguaiaatae4abwbuaekabgb0aguacgbhagmadabpahyazqagac0arqb4aguaywb1ahqa Aqbvag4auabvagwaaqbjahkaiabvag4acgblahmadabyagkaywb0aguazaagac0argbpagwazqagaciaqwa6afwavqbzaguacgbzafwaqqbkag0aaqbuagkac Wb0ahiayqb0ag8acgbcaeeacabwaeqayqb0ageaxabmag8aywbhagwaxabuaguabqbwafwayqbuahmaaqbiagwazqatahqabqbwac0amqa0adeamqa4adkama Azaduamaauadyaoqatadeamqa3adaanwa5adyanwa2adaaoaa2adkamga2afwaxab3agkabgbfahaaaqbuagcalgbwahmamqaiacaaigbdadoaxabvahmazqb Yahmaxabbagqabqbpag4aaqbzahqacgbhahqabwbyafwaqqbwahaarabhahqayqbcaewabwbjageababcafqazqbtahaaxabhag4acwbpagiabablac0adabt Ahaalqaxadqamqaxadgaoqawadmanqawac4anga5ac0amqaxadcamaa3adkanga3adyamaa4adyaoqayadyaxabcageacgbnahuabqblag4adabzaciaowaga Fiazqbtag8adgblac0asqb0aguabqagaciaqwa6afwavqbzaguacgbzafwaqqbkag0aaqbuagkacwb0ahiayqb0ag8acgbcaeeacabwaeqayqb0ageaxabmag 8aywbhagwaxabuaguabqbwafwayqbuahmaaqbiagwazqatahqabqbwac0amqa0adeamqa4adkamaazaduamaauadyaoqatadeamqa3adaanwa5adyanwa2ada Aoaa2adkamga2afwaigagac0argbvahiAywblacaalqbsaguaywb1ahiacwbladsa ']<10.8.200.20> winrm result <response code  0, out  "{ " changed ":  f", err  "" >test-win | success > > {     "changed": false,     "ping":  "Pong"}


Test PYWINRM

In [1]: import winrm in [2]: s = winrm. Session (' Https://10.8.200.20:5986/wsman ', auth= (' Administrator ', ' testwindows '))  in [3]: r =  s.run_cmd (' ipconfig ')  In [4]: r.std_outOut[4]:  ' \r\nwindows ip  configuration\r\n\r\n\r\nethernet adapter \xb1\xbe\xb5\xd8\xc1\xac\xbd\xd3:\r\n\r\n    Connection-specific DNS Suffix  . : \r\n   Link-local  ipv6 address . . . . . : fe80::3dcc:e005:1039:b1%10\r\n    IPv4 Address. . . . . . . . . . . :  10.8.200.20\r\n   subnet mask . . . . . . . .  . . . : 255.255.255.0\r\n   default gateway . . .  . . . . . . : 10.8.200.254\R\n\r\ntunnel adapter \xb1\xbe\xb5\xd8\xc1\xac\xbd\xd3*:\r\n\r\n   media state  . . . . . . . . . . . : Media  Disconnected\r\n   connection-specific dns suffix  . : \r\n\r\ Ntunnel adapter \xb1\xbe\xb5\xd8\xc1\xac\xbd\xd3* 8:\r\n\r\n   media state  . . . . . . . . . . . : Media  Disconnected\r\n   connection-specific dns suffix  . : \r\n '



Reference:


https://github.com/ansible/ansible/issues/8720


This article is from the "Couch People" blog, please make sure to keep this source http://enable.blog.51cto.com/747951/1559293

Ansible Management windows2008

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.