Ssh Ansible:无法将/etc/Ansible/hosts解析为资源清册源
我是新来的Ssh Ansible:无法将/etc/Ansible/hosts解析为资源清册源,ssh,error-handling,ansible,Ssh,Error Handling,Ansible,我是新来的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, on
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
-------我的剧本文件如下----
这是我第一次遇到这个问题。以下内容为我解决了问题:
/
cd-etc
或mkdir-etc
和cd-etc
mkdir ansible
然后cd ansible
vi主机
(然后添加主机)chmod 777主机
ansible all-m ping
在运行playbook之前,只需运行以下命令
ansible all --list-hosts
如果上述错误仍然存在,请转到/etc/ansible/ansible.cfg
,编辑指向特定主机文件的目录路径。Centos 7
这导致了上述错误:
ansible playbook-i主机测试-v tasks.yml
这修正了它:
ansible playbook-ihosttest-v tasks.yml我突然在使用多年且最近未更改的库存中遇到了同样的问题。
结果是我启用了一个插件,导致了这个问题
我启用了插件vmware\u vm\u inventory,这是消息的来源。运行ansible playbook-vvvv
我想我应该在ansible.cfg文件中定义该插件,该文件位于我运行使用该插件的playbooks的文件夹中,并将其保留在/etc/ansible/ansible.cfg主机文件中,没有读取权限,导致以下错误消息:
[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'
解决方案:更改权限
sudo chmod 744 /etc/ansible/hosts
在另一种情况下,由于主机文件的格式不正确,我收到一条错误消息:
[WARNING]: * Failed to parse /etc/ansible/hosts with yaml plugin: YAML
inventory has invalid structure, it should be a dictionary, got: <class
'ansible.parsing.yaml.objects.AnsibleUnicode'>
[WARNING]: * Failed to parse /etc/ansible/hosts with ini plugin:
/etc/ansible/hosts:3: Expected key=value host variable assignment, got: ;
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
还要检查清单文件在Ansible配置文件Ansible.cfg
中的实际位置。我遇到了相同的问题,Ansible.cfg中没有启用插件ini和yaml:
[inventory]
enable_plugins = yaml, ini
如果文件在磁盘上不存在,您将看到此错误
这将出现在-vvv
日志中:
Skipping due to inventory source not existing or not being readable by the current user
嗨,马尼,欢迎来到SO!您没有指定包含组名的文件,也没有指定正在使用的ansible版本。虽然如果它是/etc/ansible/hosts
并且您有一个现代版本的ansible,您可以分别使用ansible inventory-i/path/to/the/inventory/file-list
检查ansible对该文件的看法,ansible\u ssh\u private\u key\u file=/home/ansibleuser/.ssh
不正确,因为它指向一个目录,而不是一个文件——除非你出于某种可怕的原因在ansibleuser
的home directorylove&Le敬for ur response中将你的文件命名为.ssh
。我将ssh\u priavtekey\u文件改为/home/ansibleuser/.ssh/id\u rsa。并尝试了公共ansible inventory-i/path/to/the/inventory/file-list,得到以下响应…{u meta:{“hostvars:{”172.31.26.93:{“ansible\u ssh\u host:“172.31.26.93”,“ansible\u ssh\u pass:“vagrant”,“ansible\u ssh\u port”:22,“ansible\u ssh\u private\u key\u文件”:“/home/ansibleuser/.ssh/id\rsa”,“Ansibleu ssh_user”:“ansibleuser”,“Ansibleu user”:“vagrant”}},a:{“hosts”:[“172.31.26.93”]},all:{“children”:[“a”,“ungroup”]},ungroup:{}他问的是关于脚本的动态清单。他没有询问手动主机更新的问题文本文件不应该是chmod 777。它不需要执行权限。读取权限应足够。
[inventory]
enable_plugins = yaml, ini
Skipping due to inventory source not existing or not being readable by the current user