简体   繁体   English

Ansible。 解析 yaml。 从字符串中获取值

[英]Ansible. Parse yaml. Getting a value from a string

How do I get the mac address 00 50 79 66 68 04 from the string that is contained in the following variable?如何从以下变量中包含的字符串中获取 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 \""
   ]

Use regex_replace .使用regex_replace For example例如

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

gives

  mac: 00 50 79 66 68 04

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM