Windows配置Ansible Host
阿新 • • 發佈:2020-12-28
Windows端配置
(本文使用Ubuntu或CentOS作為管理機,Windows作為被管理機)
- 配置Windows Ansible 官方文件 。
- 跟著文件走一遍即可,關鍵部分在WinRM安裝和設定以及
Win32-OpenSSH
的安裝。 - 注意"設定WinRM偵聽器"部分,
CertificateThumbprint
要設定成自己powershell執行winrm enumerate winrm/config/Listener
輸出內容中的CertificateThumbprint
欄位。 - 其中的
Win32-OpenSSH
我選擇的是官方github wiki中的安裝教程,使用的安裝包連結。
Linux端配置Ansible測試
-
注意:
- root使用者下或sudo執行之後的命令。
- 環境:Python 2.7.5,pip install ansible==2.10.4
-
配置/etc/anshible/hosts檔案:
$sudo mkdir /etc/anshible $sudo vim /etc/anshible/hosts [test] 192.168.10.9 ansible_connection=ssh ansible_shell_type=cmd ansible_ssh_user=admin ansible_ssh_pass=123456
- 注意上面行首的
ip
和ansible_ssh_user
以及ansible_ssh_pass
Win32-OpenSSH
版本早於外殼型別v7.9.0.0p1-Beta
時ansible_shell_type=powershell
不起作用,否則只能設定ansible_shell_type=cmd
。- 其次,
Win32-OpenSSH
預設情況下Win32-OpenSSH
將cmd.exe
用作shell,設定方法在文件末尾。 - Windows檢視openssl版本方法:
cd to sshd directory (cd e:\Install\OpenSSH-Win64\OpenSSH-Win64)
.\ssh.exe -V
注意:這裡使用了
ansible_ssh_pass
sshpass
,以及Windows對應使用者要設定登入密碼(開機登陸密碼)。 - 注意上面行首的
-
安裝sshpass:
yum/apt install sshpass
-
測試ansible,使用win_ping模組,輸出如下表示配置成功:
$sudo ansible all -m win_ping 192.168.10.9 | SUCCESS => { "changed": false, "ping": "pong" }
-
Ansible Windows支援的所有模組見官方文件。
Ansible配置免密(ssh公鑰)
(目前還未成功,成功了再更新)
-
看
Configuring the Server
和Admin User
部分即可。這裡的Server指的是被遠端管理的Windows主機,Client只用來作為管理機的主機(Ansible官方不建議使用Windows作為管理機)。
注意後面的
Admin User
部分。 -
Linux啟動ssh-agent:
sudo eval ssh-agent -s sudo ssh-add