Ansible:无法解析/ etc / ansible / hosts作为库存源

问题描述 投票:2回答:2

我是ansible的新手,得到了以下问题。我能够ssh到我的客户端机器。但无法运行playbook。

得到以下错误:

[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

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

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit
localhost does not match 'all'

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

这是一个我的团体名称。我的主人在下面给出:

---------


[a]
172.31.26.93



[all:vars]

ansible_user=vagrant
ansible_ssh_pass=vagrant


 ansible_ssh_host=172.31.26.93
 ansible_ssh_port=22
 ansible_ssh_user='ansibleuser'
 ansible_ssh_private_key_file=/home/ansibleuser/.ssh

-------我的剧本文件如下----

- hosts: a
  tasks:
  - name: create a directory
    file: path=/home/ansiblesuser/www state=directory

这是我第一次遇到这个问题。

ssh error-handling ansible
2个回答
1
投票

在运行playbook之前,只需运行以下命令

ansible all --list-hosts

如果上述错误仍然存​​在,请转到/etc/ansible/ansible.cfg并编辑指向特定主机文件的inventory路径。


0
投票

以下为我解决了这个问题:

  1. 转到根目录/
  2. cd etcmkdir etccd etc
  3. mkdir ansible然后cd ansible
  4. vi hosts(然后添加主机)
  5. chmod 777 hosts
  6. 检查ansible all -m ping
© www.soinside.com 2019 - 2024. All rights reserved.