I am trying to play with Ansible a little bit and I’ve created a test playbook but it is failing for some reason and I can’t figure out why. I’ve tested the connectivity between my control node and the worker node but when I try to run my playbook I get this error:
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to have been in '/root/ansible/setup.yaml': line 9, column 12, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Apache started
service:
^ here
I can not see anything wrong with the service part in my playbook. Here’s what I currently have:
---
- hosts: webservers
vars:
my_service: apache2
desired_state: started
tasks:
- name: Apache started
service:
name: "{{ my_service }}"
state: "{{ desired_state }}"
Has anyone seen this error before?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hello,
The playbook looks good, there’s only a slight indentation error, Yaml is very strict about the indentations and the spacing.
You need to make sure that you have two spaces before the
- name
part of your playbook. So it would look something like this:Hope that this helps! Regards, Bobby
check the ansible version and upgrade it and check python version also as stack require higher version of ansible and python
Hello, I am getting a similar error with td-agent file. I checked on various pages but not clear yet.
ERROR: ERROR! 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. did not find expected <document start>
The error appears to be in '/address/to/path/log-aggregator.yml: be elsewhere in the file depending on the exact syntax problem.