【问题标题】:Running Ansible setup module without an ansible.cfg在没有 ansible.cfg 的情况下运行 Ansible 设置模块
【发布时间】:2019-07-28 13:38:32
【问题描述】:

我想通过声明一个特定的主机来运行 ansible 设置模块。

我使用的是 Windows 10 机器,带有安装了 ansible 的 linux 的 windows 子系统。

我可以在使用localhost时运行设置模块,即:

ansible localhost -m setup

我可以在使用我在一个虚拟环境中使用的 ansible.cfg 文件时针对虚拟机运行它,即:

ansible TestVm -m setup

在另一个虚拟环境中,我安装了 ansible 而没有设置 ansible.cfg 文件,并且我的 hosts.yml 文件在 windows 中(不是 WSL 文件系统)。

无论我切换哪个目录,我都无法运行安装模块,例如:

ansible -i inventory -m setup

.

有没有办法在没有配置文件的情况下运行安装程序,如果是的话,我错过了调用的哪一部分?

【问题讨论】:

  • 您遇到的错误是什么?当您指定 -i 时,您可能需要将其定向到正确的主机文件。在这种情况下,如果 hosts.yml 在 Windows 中,则文件路径将类似于 /mnt/<drive letter>/path
  • 我已经挂载了 C 盘,并在包含 host.yml 的目录中运行它。我收到的错误消息是“错误!缺少目标主机”。它似乎无法识别我的主机,但我找不到如何指向我想要的主机。

标签: ansible windows-subsystem-for-linux


【解决方案1】:

试试这个:

ansible all -i inventory -m setup

清单是至少包含 hosts.yml 文件的目录。

这是 hosts.yml

的示例
all:
  hosts:
    192.168.2.9:
    192.168.2.3:
    192.168.2.4:

此外,您必须在其中任何一个之前添加 pywinrm:

pip install pywinrm

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 1970-01-01
    • 2013-01-31
    • 2019-11-15
    • 1970-01-01
    相关资源
    最近更新 更多