【问题标题】:Ansible. Parse yaml. Getting a value from a string [closed]安西布尔。解析yaml。从字符串中获取值[关闭]
【发布时间】:2022-02-04 18:41:24
【问题描述】:

如何从以下变量中包含的字符串中获取mac地址00 50 79 66 68 04?

"oid.stdout_lines": [
       "iso.3.6.1.2.1.17.4.3.1.1.0.80.121.102.104.4 \"00 50 79 66 68 04 \""
   ]

【问题讨论】:

  • 期望结果:00 50 79 66 68 04
  • 如果您指定操作系统、语言或声明不偏好语言,这会有所帮助。展示你迄今为止尝试过的内容。

标签: regex ansible yaml


【解决方案1】:

使用 regex_replace。例如

  _regex: '.*"(.*)"'
  _replace: '\1'
  mac: "{{ oid.stdout_lines|first|regex_replace(_regex, _replace)|trim }}"

给予

  mac: 00 50 79 66 68 04

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 2019-02-10
    相关资源
    最近更新 更多