如何解决Ansible-错误!我们无法读取JSON或YAML
在本教程Deploy a Windows VM to Azure with Ansible的Step 3 - Create a Public IP
中,当我在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 }}"
更新
仅注意到您问题中引用的链接上的示例。这些示例描述了与azure_rm_publicipaddress_module的Ansible模块文档中的示例不同的语法(缩进)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。