ansible - ERROR! We were unable to read either as JSON nor YAML
If it is not a copy+paste issue, I think the indentation on your tasks is not valid. In Ansible tasks:
is a YAML list. So the list items should be indented appropriately.
Something like this:
---
- hosts: localhost
tasks:
- name: Create public IP address
azure_rm_publicipaddress:
resource_group: rg-cs-ansible
allocation_method: Static
name: pip-cs-web
register: output_ip_address
- name: Output public IP
debug:
msg: "The public IP is {{ output_ip_address.state.ip_address }}"
Update
Just noticed the examples on the link referenced in your question. Those examples depict a different syntax (indentation), from the examples on Ansible module documentation for azure_rm_publicipaddress_module.
Related videos on Youtube
nam
Updated on June 04, 2022Comments
-
nam almost 2 years
In
Step 3 - Create a Public IP
of this tutorial Deploy a Windows VM to Azure with Ansible, I am getting the error shown below when I run the followingYAML playbook
inAzure Cloud Shell
. Question: What I may be missing here that's causing this error, and how it can be corrected? I saw similar issue online here but it did not help since I'm not making the mistake mentioned in that online post.create_public_ip.yaml:
--- - hosts: localhost tasks: - name: Create public IP address azure_rm_publicipaddress: resource_group: rg-cs-ansible allocation_method: Static name: pip-cs-web register: output_ip_address - name: Output public IP debug: msg: "The public IP is {{ output_ip_address.state.ip_address }}"
Error:
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each: JSON: No JSON object could be decoded Syntax Error while loading YAML. mapping values are not allowed here The error appears to be in '/home/myAcctName/clouddrive/MyDir/create_public_ip.yaml': line 5, column 29, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: - name: Create public IP address azure_rm_publicipaddress: ^ here
-
Zeitounator over 3 yearsYour playbook does not respect yaml and/or ansible syntax. Please take Y minutes to learn yaml and pay attention to indentation and new lines. You should also read through the Intro to playbooks to learn the basic concepts and syntax. You can validate your playbooks with yamllint and ansible-lint prior to posting.
-
-
nam over 3 yearsYour suggestion worked (thank you). When you say "the examples in the referenced link depict a different syntax (indentation), from the examples on Ansible module documentation", you mean referenced link is using different version and now the syntax in new version has changed? I'm new to ansible.
-
seshadri_c over 3 yearsNo. I think they got the indentation wrong (somehow) in their examples. The ones on Ansible are the correct ones.