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

查看:209
本文介绍了已指定直接主机的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天全站免登陆