1. 程式人生 > 實用技巧 >Windows配置Ansible Host

Windows配置Ansible Host

Windows端配置

​ (本文使用Ubuntu或CentOS作為管理機,Windows作為被管理機

  1. 配置Windows Ansible 官方文件
  2. 跟著文件走一遍即可,關鍵部分在WinRM安裝和設定以及Win32-OpenSSH的安裝。
  3. 注意"設定WinRM偵聽器"部分,CertificateThumbprint 要設定成自己powershell執行winrm enumerate winrm/config/Listener輸出內容中的CertificateThumbprint 欄位。
  4. 其中的Win32-OpenSSH我選擇的是官方github wiki中的安裝教程,使用的安裝包連結

Linux端配置Ansible測試

  1. 注意:

    • root使用者下或sudo執行之後的命令。
    • 環境:Python 2.7.5,pip install ansible==2.10.4
  2. 配置/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
    
    • 注意上面行首的ipansible_ssh_user以及ansible_ssh_pass
      要改成自己Windows主機的資訊。
    • Win32-OpenSSH版本早於外殼型別v7.9.0.0p1-Betaansible_shell_type=powershell不起作用,否則只能設定ansible_shell_type=cmd
    • 其次,Win32-OpenSSH預設情況下Win32-OpenSSHcmd.exe用作shell,設定方法在文件末尾。
    • Windows檢視openssl版本方法:
      1. cd to sshd directory (cd e:\Install\OpenSSH-Win64\OpenSSH-Win64)
      2. .\ssh.exe -V

    注意:這裡使用了ansible_ssh_pass

    ,所以後面要安裝sshpass,以及Windows對應使用者要設定登入密碼(開機登陸密碼)。

  3. 安裝sshpass:yum/apt install sshpass

  4. 測試ansible,使用win_ping模組,輸出如下表示配置成功:

    $sudo ansible all -m win_ping
    192.168.10.9 | SUCCESS => {
        "changed": false,
        "ping": "pong"
    }
    
  5. Ansible Windows支援的所有模組見官方文件

Ansible配置免密(ssh公鑰)

​ (目前還未成功,成功了再更新)

  1. Windows Openssh配置ssh免密登入問題

    Configuring the ServerAdmin User部分即可。

    這裡的Server指的是被遠端管理的Windows主機,Client只用來作為管理機的主機(Ansible官方不建議使用Windows作為管理機)。

    注意後面的Admin User部分。

  2. Linux啟動ssh-agent:

    sudo eval ssh-agent -s
    sudo ssh-add