Ansible 操做windows

 
一、主控端安裝ansible
        1) pip install ansible
二、主控端安裝相關的包
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
三、配置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"}'
                
四、修改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
相關文章
相關標籤/搜索