Inventory
Ansible’s支持windows需要依赖于少量标准变量来表明远程主机的username, password, and connection type (windows).这些变量大部分都很容易被设置好.在 Ansible 中通过用来代替 SSH-keys 或 密码输入:
[windows]
winserver1.example.com
winserver2.example.com在 group_vars/windows.yml,定义如下 inventory 变量:
# it is suggested that these be encrypted with ansible-vault:
# ansible-vault edit group_vars/windows.yml
ansible_ssh_user: Administrator
ansible_ssh_pass: SecretPasswordGoesHere
ansible_ssh_port: 5986
ansible_connection: winrm需要注意的是这里的 ssh_port 不是真正的SSH协议的端口,but this is a holdover variable name from how Ansible is mostly an SSH-oriented system.(这句也没看懂)再重复一遍,Windows 管理主机不是通过SSH协议.
如果你已经安装了 kerberos 模块和 ansible_ssh_user 包括 @ (e.g. username@realm), Ansible会先尝试Kerberos认证. 这种方式主要用你通过Kerberos在远程主机上的认证而不是 ansible_ssh_user .如果上述办法失败了,要么是因为你没有在管理机上签署(signed into)Kerberos,要么是因为远程主机上对应的域帐户不可用,接着 Ansible 将返回原始(“plain”)username/password的认证方式.
当你使用 playbook 时,请不要忘记指定 –ask-vault-pass 提供密码来解锁文件.
使用如下命令来测试你的配置,尝试连接你的 Windows 节点.注意:这不是ICMP ping,只是利用 Windows 远程工具来检测 Ansible 的信道是否正常:
ansible windows [-i inventory] -m win_ping --ask-vault-pass如果你还没有在你的系统上做任何准备工作,那上面的命令是无法正常工作的. 在下面最近的章节将会介绍 “how to enable PowerShell remoting” - 如果有需要的话也将介绍 “how to upgrade PowerShell to a version that is 3 or higher” .
你可以稍后再执行该命令,以确保一切都能正常工作.
学员评价