日常工作中,我们大部分时间都是在 Linux 服务器中部署我们自己的产品,但是偶尔也会有很多服务是基于 .NET 开发的,基于 .NET 开发的产品,我们无法运行在 Linux 服务器中,只能在 Windows 中运行,如果此时业务需要有大量的 Windows 服务器需要我们操作,那将是一件很蛋疼的事情,Linux 下,我们可以通过各种脚本、多 shell 终端等进行批量操作,而 Windows 服务器则很少或者没有这样的操作,那怎么办呢?一台台服务器去操作无疑是浪费时间,耗费精力,这时候,我们的 Ansible 就可以派上大用场了,下面,我们介绍,如何通过 Ansible 进行 Windows 服务器操作。

1、在 Windows 服务器中新建一个可供 Ansible 登录的用户,比如就叫 ansible ,并授予 administrator 权限。

图片.png图片.png

2、打开 cmd 或者 powershell,执行以下命令:

winrm enumerate winrm/config/listener

图片.png

winrm quickconfig

图片.png

winrm set winrm/config/service/auth '@{Basic="true"}'

图片.png

winrm set winrm/config/service '@{AllowUnencrypted="true"}'

图片.png

3、在 Ansible 上进行 hosts 配置

192.168.0.58 ansible_ssh_user="ansible" ansible_ssh_pass="123456" ansible_ssh_port="5985" ansible_connection="winrm" ansible_winrm_server_cert_validation="ignore"

4、验证

图片.png