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_MACHINESOFTWAREMicrosoftPowerShell1ShellIdsMicrosoftPowerShell
4) 下载并运行https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1
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