添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am new to ansible , got the below issue. I was able to ssh into my client machine .but unable to run playbook.

Getting the error below:

[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

here a is my group name. my hosts given below :

---------
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

------- my playbook file given below ----

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

This is the first time I am getting this issue.

Hi Mani, welcome to SO! You didn't specify the file that contains your group name, nor the version of ansible you are using. Although if it is /etc/ansible/hosts and you have a modern version of ansible, you can check to see what ansible sees about that file using ansible-inventory -i /path/to/the/inventory/file --list – mdaniel Nov 9, 2018 at 4:30 Separately, ansible_ssh_private_key_file=/home/ansibleuser/.ssh is incorrect as that points to a directory, and not to a file -- unless you have for some terrible reason named your file as .ssh in ansibleuser's home directory – mdaniel Nov 9, 2018 at 4:31 I changed the ssh_priavtekey_file to /home/ansibleuser/.ssh/id_rsa. and tried the the commond ansible-inventory -i /path/to/the/inventory/file --list , got below response ... – MANI KANTA Nov 9, 2018 at 10:26 { "_meta": { "hostvars": { "172.31.26.93": { "ansible_ssh_host": "172.31.26.93", "ansible_ssh_pass": "vagrant", "ansible_ssh_port": 22, "ansible_ssh_private_key_file": "/home/ansibleuser/.ssh/id_rsa", "ansible_ssh_user": "ansibleuser", "ansible_user": "vagrant" } } }, "a": { "hosts": [ "172.31.26.93" ] }, "all": { "children": [ "a", "ungrouped" ] }, "ungrouped": {} } – MANI KANTA Nov 9, 2018 at 10:31

i had the same issue, the plugins ini and yaml were not enable in the ansible.cfg :

[inventory]
enable_plugins = yaml, ini
                You just saved me a solution for weeks of effort.  I could add a medal to this one.  If i had known what to search for i would have found it faster, lol.   keyword = multiple hosts, combine dynamic and static hosts. e.g. enable_plugins = aws_ec2, yaml, ini, inventory=./inventory and all inventory files, including aws_ec2.yml inside inventory/
– blamb
                Mar 9 at 14:38

I suddenly experienced the same issue with an inventory that was many years in use and hadn't changed recently. It turned out I enabled a plugin which caused this issue.

I enabled the plugin vmware_vm_inventory which was the source of the message. This showed up by running ansible-playbook -vvvv <host>

I'd figured I should define the plugin in an ansible.cfg file that is present in the folder where I run playbooks that use this plugin and leave it out of the /etc/ansible/ansible.cfg

He was asking about dynamic inventory with script. He was not asking about manual host update – EagleDev Mar 1, 2019 at 0:03

If you are still having this issue when you run

ansible-playbook -i path/to/inventory/file playbook.yml

Simply create an empty ansible.cfg file in the directory where you have your playbook.

Using ansible version ansible 2.9.27 able to resolve by giving complete (absolute path) for me error is like below

[WARNING]: Unable to parse /root/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: all

Use following command

ansible-playbook -i /etc/ansible/hosts showfiles.yml

Host file with no read permissions caused the following error message:

[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'

Solution: change permissions

sudo chmod 744 /etc/ansible/hosts 

In another occasion I got an error message due to an incorrect formatting of the hosts file:

[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

and I fixed the issue by correcting the format error.

As suggested in another answer check if hosts are available with

ansible all --list-hosts

Also check the actual location of the inventory file in the Ansible configuration file ansible.cfg.

You'll see this error if the file doesn't exist on disk as well.

This will be in the -vvvv log:

Skipping due to inventory source not existing or not being readable by the current user

The problem with mine was that, I try to commen someof the configuration. Which creates the problem. Just remove it and works fine.

I know its not specific solution of problem here, but just write it down to point out possible cause for other. Thanks

The solution was Space issues in Token

`$ ansible-playbook -i inventory/forem/setup.yml playbooks/providers/aws.yml [WARNING]: * Failed to parse /var/home/core/selfhost/inventory/forem/setup.yml with ini plugin: Invalid host pattern '---' supplied, '---' is normally a sign this is a YAML file. [WARNING]: * Failed to parse /var/home/core/selfhost/inventory/forem/setup.yml with yaml plugin: We were unable to read either as JSON nor YAML, these are the errors we got from each: JSON: Expecting value: line 1 column 1 (char 0) Syntax Error while loading YAML. could not find expected ':' The error appears to be in '/var/home/core/selfhost/inventory/forem/setup.yml': line 85, column 11, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: $ANSIBLE_VAULT;1.1;AES256 62376137383864393461613561353234643230666431643935303533346631393537363564366334 ^ here [WARNING]: Unable to parse /var/home/core/selfhost/inventory/forem/setup.yml 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'

PLAY [Deploy Forem to AWS]

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.