Ansible:无法将/ etc / ansible / hosts解析为清单资源

MAN*_*NTA 4 error-handling ssh ansible

我是新手ansible,遇到了以下问题。我可以ssh进入客户端计算机。但是无法运行剧本。

得到以下错误:

[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
Run Code Online (Sandbox Code Playgroud)

这是我的群组名称。我的主机如下:

---------


[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
Run Code Online (Sandbox Code Playgroud)

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

- hosts: a
  tasks:
  - name: create a directory
    file: path=/home/ansiblesuser/www state=directory
Run Code Online (Sandbox Code Playgroud)

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

小智 5

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

ansible all --list-hosts
Run Code Online (Sandbox Code Playgroud)

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


小智 5

我有同样的问题,插件 ini 和 yaml 在 ansible.cfg 中未启用:

[inventory]
enable_plugins = yaml, ini
Run Code Online (Sandbox Code Playgroud)


Bai*_*osh 0

以下为我解决了问题:

  1. 进入根目录/
  2. cd etcmkdir etccd etc
  3. mkdir ansible然后cd ansible
  4. vi hosts(然后添加主机)
  5. chmod 777 hosts
  6. 查看ansible all -m ping

  • 文本文件不应是 chmod 777。它不需要执行权限。 (5认同)
  • 他正在询问带有脚本的动态库存。他没有询问手动主机更新 (3认同)