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

标签 azure ansible azure-cloud-shell

Step 3 - Create a Public IP本教程的内容 Deploy a Windows VM to Azure with Ansible ,当我运行以下命令时收到如下所示的错误 YAML playbookAzure Cloud Shell问题:我可能遗漏了什么导致此错误,以及如何纠正它?我在网上看到类似的问题here但这没有帮助,因为我没有犯该在线帖子中提到的错误。

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 }}"

更新

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

关于azure - ansible - 错误!我们无法读取 JSON 或 YAML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64584578/

相关文章:

azure - 为什么 Azure Cloud Shell 在默认订阅中创建资源组?

c# - 将 mvc 应用程序发布到 Azure 时出现错误

sql - 如何在 AZURE DW 或 Azure synapse 中创建用户或角色特定的触发器?

Ansible-pull,没有库存限制

windows - 如何从Powershell到Ansible获取负返回码

python - 在 Python3 上是否有 Ansible 的替代品

azure - 从 Azure Cloud Shell 显示所有 Azure Web Apps 自定义域的列表

azure - Get-AzureRmVM 需要名称参数吗?

azure - 如何使用 Odata 链接服务将文件从共享点复制到 Blob 存储 Azure 数据工厂 v2

azure - 添加 WebRole.cs - 并调用它 - 在转换为 Web 角色的现有 ASP.NET MVC 站点中