在 Step 3 - Create a Public IP
本教程的内容 Deploy a Windows VM to Azure with Ansible ,当我运行以下命令时收到如下所示的错误 YAML playbook
在Azure 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/