1
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
sudo nano /etc/ansible/hosts

Edited the file as:

[Webserver] 192.168.27.1

[servers] host1 ansible_ssh_host: 192.168.27.1 Then

sudo mkdir /etc/ansible/group_vars
sudo nano /etc/ansible/group_vars/servers

Yaml file is created as:

   ---
   ansible_ssh_user: root

Then:

ansible -m ping all

and the error that I encountered is as:

ERROR! Attempted to read "/etc/ansible/hosts" as YAML: Syntax Error while loading YAML.


The error appears to have been in '/etc/ansible/hosts': line 46, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

[Webserver]
192.168.27.1
^ here

Attempted to read "/etc/ansible/hosts" as ini file: /etc/ansible/hosts:50: Expected key=value host variable assignment, got: 192.168.27.1 

Please help me resolve this problem.

1 Answer 1

2

Looks exactly like this try to go into the file and search for a misplaced whitespace in that line. The root cause was for a leading space in /usr/local/etc/ansible/hosts file and the solution was searching for such spaces and remove them. The key part of the forum post is noted down below.

This is caused by comments with leading whitespace in the /usr/local/etc/ansible/hosts inventory file. This is new behavior for this Ansible version!

So if you're in the habit of writing something like this in that hosts file:

[web]
     # legacy servers
     webserver-[1:2].company.com

Change it into:

[web]
# legacy servers
     webserver-[1:2].company.com

or

[web]
     webserver-[1:2].company.com # legacy servers
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .