可靠的。解析 yaml。从字符串中获取值

Ansible. Parse yaml. Getting a value from a string

如何从包含在以下变量中的字符串中获取 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 \""
   ]

使用regex_replace。例如

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

给予

  mac: 00 50 79 66 68 04