ansible - ERROR! We were unable to read either as JSON nor YAML [closed]
Asked Answered
T

1

5

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 following YAML playbook in Azure 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
Therapy answered 29/10, 2020 at 3:29 Comment(2)
Your 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.Uppity
I encountered this error when one of the three dashes --- at the top of the file had gone missing. Syntax error.Dressmaker
P
7

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.

Parmenter answered 29/10, 2020 at 4:31 Comment(2)
Your 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.Therapy
No. I think they got the indentation wrong (somehow) in their examples. The ones on Ansible are the correct ones.Parmenter

© 2022 - 2024 — McMap. All rights reserved.