Search code examples
azureansibleazure-cloud-shell

ansible - ERROR! We were unable to read either as JSON nor YAML


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

Solution

  • 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.