vec*_*cin 5 windows ansible ansible-2.x
我已经在 Windows 10 工作站的 WSL(Linux 的 Windows 子系统)中安装了 Ansible。
我的目标是同时配置 WSL 和 Windows 10 本身。
我能够针对本地主机运行剧本,它通过 SSH 连接和配置 WSL。
但是,我不确定 Ansible 是否可以针对 Windows 主机运行 playbook,以便能够自行设置 Windows(例如,使用 Chocolatey 安装软件包)
这甚至可能吗?或者 Ansible 只能在安装在不同的 Linux 机器上时设置 Windows 节点?
Great! I was able to connect to my windows host after following those steps.
However, I had to solve two more issues before I was able to run ansible playbooks against both, WSL and windows host:
Windows host uses ansible_connection=winrm, but for WSL needs a different connection, I've set ansible_connection=local.
The ansible_connection var is overridden. This is because the var name and the host name is the same. This means that you can either run a playbook for WSL or for Windows host but not against both, as they need different connection.
To fix that you can either set hash-behaviour, or set two different host names for localhost under your WSL, /etc/hosts. I've done the second one:
127.0.0.1 wsl.local
127.0.0.1 windows.local
Run Code Online (Sandbox Code Playgroud)
My /etc/ansible/hosts:
[wsl]
wsl.local
[wsl:vars]
ansible_connection=local
[windows]
windows.local
[windows:vars]
ansible_port=5985
ansible_connection=winrm
ansible_winrm_transport=basic
ansible_user=<<ansible_user>>
ansible_password=<<ansible_password>>
Run Code Online (Sandbox Code Playgroud)
现在,我可以运行 ansible_playbook,其中包含针对 Windows 主机和 WSL 运行的任务。此处了解有关配置的更多详细信息。
是的,这是可能的。
$ apt install python-pip$ pip install pywinrm $ pip install xmltodictEnable-PSRemoting -SkipNetworkProfileCheck但我不建议这样做。Enable-PSRemoting在 Windows 的 PowerShell 中运行它。Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value $trueSet-Item -Path WSMan:\localhost\Service\AllowUnencrypted -Value $trueansible_port: 5985
ansible_connection: winrm
ansible_winrm_transport: basic
Run Code Online (Sandbox Code Playgroud)
ansible_user=your_win_user并/ansible_password=your_win_user_pass或在之前的变量中对它们进行硬编码。我使用此设置从 WSL 配置我的计算机。你可以在这里看看。希望这可以帮助。