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

nam*_*nam 5 azure ansible azure-cloud-shell

Step 3 - Create a Public IP本教程使用 Ansible 将 Windows VM 部署到 Azure 中,当我YAML playbookAzure Cloud Shell. 问题:我可能缺少什么导致了这个错误,以及如何纠正它?我在网上看到了类似的问题,但它没有帮助,因为我没有犯该在线帖子中提到的错误。

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 }}"
Run Code Online (Sandbox Code Playgroud)

错误

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
Run Code Online (Sandbox Code Playgroud)

ses*_*i_c 7

如果不是复制+粘贴问题,我认为您的任务上的缩进无效。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 }}"
Run Code Online (Sandbox Code Playgroud)

更新

刚刚注意到您问题中引用的链接上的示例。这些示例描述了与azure_rm_publicipaddress_module的 Ansible 模块文档中的示例不同的语法(缩进)。