指定了直接主机的 Ansible ad-hoc 命令 - 没有匹配的主机 [英] Ansible ad-hoc command with direct host specified - no hosts matched

查看:18
本文介绍了指定了直接主机的 Ansible ad-hoc 命令 - 没有匹配的主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VirtualBox 运行 16.04 Ubuntu 桌面计算机.此 VM 已安装 Ansible 2.4.0.我正在尝试运行一个特别的 ansible 命令来证明它有效(我正在做一个在线课程).为了模拟一个小型服务器群,我使用 lxc(linux 容器)并运行其中三个:

I am running a 16.04 Ubuntu desktop machine using VirtualBox. This VM has Ansible 2.4.0 installed. I am trying to run an ad-hoc ansible command just to prove it works (I am doing an online course). To simulate a small server farm, I use lxc (linux containters) and have three of them running:

root@tomasz-VirtualBox:/home/tomasz/ansible# lxc-ls --fancy
NAME STATE   AUTOSTART GROUPS IPV4       IPV6 
db1  RUNNING 0         -      10.0.3.248 -    
web1 RUNNING 0         -      10.0.3.110 -    
web2 RUNNING 0         -      10.0.3.226 -

我可以通过 SSH 连接到这些服务器中的任何一个,但是当我尝试运行一次性 ansible 命令时,例如:

I can SSH to any of these servers, however when I try to run a one-off ansible command, for example:

root@tomasz-VirtualBox:/home/tomasz/ansible# ansible 10.0.3.248 -m ping -u ubuntu

我收到以下错误,即没有匹配的库存:

I get the following errors, that no inventory has been matched:

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available

 [WARNING]: Could not match supplied host pattern, ignoring: 10.0.3.248

 [WARNING]: No hosts matched, nothing to do

老实说,我很困惑,作为 Ansible 的新手,我不知道如何向前推进.看起来很简单的问题,在stackoverflow上还没有遇到任何类似的事情.非常感谢您的任何提示!

I am puzzled, to be honest, and as an Ansible novice, I have no idea how to move this forward. Seems such a simple issue, have not come across any similar thing here on stackoverflow. Many thanks for any hints!

推荐答案

我直接在命令中提供了这个主机的 IP 地址.在这种情况下,根据我的理解,库存文件是无关紧要的.

I provide this host's IP address directly in the command. In this very case, according to my understanding, the inventory file is irrelevant.

错了.您指定 主机模式,它应该与您的清单中的主机相匹配.清单是 Ansible 的必备条件.

Wrong. You specify host pattern, which should match hosts in your inventory. Inventory is a must for Ansible.

有一个选项可以指定内嵌"广告资源.对于您的情况:

There's an option to specify "inline" inventory. For your case:

ansible all -i '10.0.3.248,' -m ping -u ubuntu

在这个例子中:主机模式是all,清单是单个主机的列表10.0.3.248.
注意末尾的逗号 - 这很重要,这样 Ansible 就可以理解它是内联清单,而不是文件路径.

in this example: host pattern is all, inventory is a list of a single host 10.0.3.248.
Note comma at the end – it is important, this way Ansible understand that it is inline inventory, and not path to file.

这篇关于指定了直接主机的 Ansible ad-hoc 命令 - 没有匹配的主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆