Automation tools like Ansible make use of playbooks to send commands to remote computers using scripts.

It primarily use Hosts while executing the commands. Often due to incorrect command syntax or missing hosts, it ends up in “Ansible-playbook error missing target hosts.

At Bobcares, we often get requests to fix Ansible-playbook errors, as a part of our Server Management Services.

Today, let’s see how our Support Engineers fix “Ansible-playbook error missing target hosts”.

 

Causes for the error and how we fix it

In the era of automation, Ansible makeit really simple to automate apps and IT infrastructure.

Usually, the error occurs when you are trying to execute the ansible-playbook. Playbooks are files where we write Ansible codes. Playbooks are written in YAML format.

Let us discuss the top 3 causes for the error and how our Support Engineers resolve it.

 

1. Incorrect command used

One of the common mistakes comes up in the usage of the command. Incorrect syntax will result in an error. Our Support Engineers always double-check the commands that we execute on the server.

The correct syntax to run a playbook is:

ansible-playbook -i hosts playbook_name.yml

 

2. Hosts not added properly

Recently we had a customer who was facing the error “ansible-playbook error missing target hosts”. On analyzing the error, hosts entry was incorrect.
Ansible hosts file is at the location:

/etc/ansible/hosts

The location of the file can change based on the ansible configuration. The hosts entry needs to be right for the ansible-playbook command to recognize it.

The correct format to enter the hosts entry in the file is:

After correcting the hosts entry, the deployment started working fine.

 

2. Syntax error in the playbook

Another common reason for the error is because of incorrect syntax in the playbook. We can mention the hosts name in the playbook as well. When mentioning the host in playbook the syntax needs to be right. The common reason for the syntax error is in the use of <space>.

- name: Configure webserver with git
  hosts: hostsname

[Stuck with ansible related errors? We are here to help you 24×7.]

 

Conclusion

In short, we have discussed the common causes for the error “ansible-playbook error missing target hosts”. Also, we have saw how our Support Engineers identify and resolve it.



Source link

Author

Write A Comment