Ansible 操作windows


 
1、主控端安裝ansible
        1) pip install ansible
2、主控端安裝相關的包
pip  install  http://github.com/diyan/pywinrm/archive/master.zip#egg=pywinrm
apt-get  install   libkrb5-dev
pip  install   kerberos
          pip install paramiko PyYAML Jinja2 httplib2 six
3、配置windows
        1) 升級到.net 3.0以上
            下載鏈接為:http://download.microsoft.com/download/B/A/4/BA4A7E71-2906-4B2D-A0E1-80CF16844F5F/dotNetFx45_Full_x86_x64.exe。 下載至本地后雙擊左鍵安裝即可,期間可能會多次重啟,電腦需正常連接Internet。
        2) 升級到powershell 3.0以上
            下載鏈接為 https://github.com/cchurch/ansible/blob/devel/examples/scripts/upgrade_to_ps3.ps1,下載后在powershell中執行就可以了
        3) 執行$host和$psversiontable查看版本,ps是$host的Version,.net是$psveriontable的CLRVersion
                
        4) 更改powershell策略為remotesigned
            set-executionpolicy remotesigned
            
            或者修改注冊表HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft\PowerShell
                

 

        5) 在powershell中執行winrm qc啟動winrm
        6) 在cmd中執行   
            > winrm set winrm/config/service '@{AllowUnencrypted="true"}'
            > winrm set winrm/config/service/auth '@{Basic="true"}'
                
4、修改ansible服務端
        1) 修改默認得到Inventory /etc/ansible/hosts,添加
            [windows]
            192.168.56.101 ansible_ssh_user="Administrator" ansible_ssh_pass="geely@2018" ansible_ssh_port=5985 ansible_connection="winrm" ansible_winrm_server_cert_validation=ignore
        2) 測試:
                ansible 192.168.56.101 -m win_ping  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM