ansible - 错误!我们无法读取 JSON 或 YAML

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

在本教程的 Step 3 - Create a Public IPDeploy 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 但它没有帮助,因为我没有犯在线 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! 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

如果不是复制粘贴的问题,我认为你的任务缩进是无效的。在 Ansible 中 tasks: 是一个 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 }}"

更新

刚刚注意到您问题中引用的 link 中的示例。这些示例描述了与 azure_rm_publicipaddress_module.

的 Ansible 模块文档示例不同的语法(缩进)