【问题标题】:can an IP address be used in YAML可以在 YAML 中使用 IP 地址吗
【发布时间】:2018-08-06 13:30:35
【问题描述】:
---
- hosts: 192.168.1.1
  tasks:
  - name: run show version on remote devices
   ios_command:
     commands: show version

错误:在此上下文中的第 2 行列中不允许映射值 9

我在这个语法上到底做错了什么?是否可以在这里使用 IP 而不是 DNS?

【问题讨论】:

  • 您可能想尝试转义 IP(明确表示它是一个字符串):hosts: "192.168.1.1"
  • 你需要正确缩进你的 YAML。
  • ios_command: 行需要缩进一个空格

标签: yaml


【解决方案1】:

是的,您可以使用像192.168.1.1 这样的 IP,它将被识别为字符串(在解析过程中,只要遇到第二个点,这使其不是浮点数。

您文件中的问题在于ios_command 的缩进,其i 必须与name 中的n 对齐:

---
- hosts: 192.168.1.1
  tasks:
  - name: run show version on remote devices
    ios_command:
     commands: show version

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-28
    • 2019-08-18
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多