ansible server(linux) 需要安装 pywinrm
pip3 install pywinrm
被控机(windows win-10)开启winrm 服务
管理员打开powershell,执行以下命令:
set-executionpolicy remotesigned # 必须执行
winrm quickconfig # 必须执行
winrm set winrm/config/service/auth '@{Basic="true"}' # 必须执行
winrm set winrm/config/service '@{AllowUnencrypted="true"}' #配置加密方式为允许非加密
netstat -ano | findstr 5985 #查看winrm端口是否启用
netsh http show servicestate #HTTP 服务状态快照(服务器会话视图) (非必须执行)
设置 -- 账户 -- 其他用户 -- 将其他人添加到这台电脑 -- 我没有这个人的登录信息 -- 添加一个没有 Microsoft 帐户的用户 -- 输入用户名、密码、安全问题... -- 更改账户类型 (选管理员)
baron@L171:~/ansible_server$ cat hosts
[windows]
192.168.0.56
[windows:vars]
ansible_ssh_user=baron #windows上新建的用户名
ansible_ssh_port=5985
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
为了信息安全未配置密码
baron@L171:~/ansible_server$ ansible -i hosts windows -m win_ping -v -k
No config file found; using defaults
SSH password:
192.168.0.56 | SUCCESS => {
"changed": false,
"ping": "pong"
}
往被控机上复制目录
baron@L171:~/ansible_server$ ansible -i hosts windows -m win_copy -a "src=/home/static/tmp dest=D:\\\tmp"
192.168.0.56 | CHANGED => {
"changed": true,
"dest": "D:\\tmp",
"operation": "folder_copy",
"src": "/home/static/tmp"
}
192.168.0.56 | UNREACHABLE! => {
"changed": false,
"msg": "plaintext: the specified credentials were rejected by the server",
"unreachable": true
}
网上查询资料说在hosts中的windows:vars 中加上 ansible_winrm_transport=ntlm
然而并没有用:
192.168.0.56 | UNREACHABLE! => {
"changed": false,
"msg": "ntlm: the specified credentials were rejected by the server",
"unreachable": true
}
终于看到了这个,抱着试试看的态度,就把问题解决了