ansible - 如何解析ansible的输出
问题描述
我的播放列表有以下比赛
- set_fact:
ip={{output_result.cmd | regex_findall('[0-9./]+') | list}}
register: ip_result
- debug:
var: ip_result.ansible_facts.ip
并低于输出(它带有与之关联的 IP 和端口。)
TASK [debug]
*********************************************************
ok: [localhost] => {
"ip_result.ansible_facts.ip": [
"192.168.2.157",
"3306"
]
但我不能只得到192.168.2.157,我该如何使用ansible?
我也尝试设置 regex_search 而不是 regex_findall
ip={{output_result.cmd| regex_search('[0-9./]+') | list}}
但是我得到的输出就像
TASK [debug]
****************************************************************
ok: [localhost] => {
"ip_result.ansible_facts.ip": [
"1",
"9",
"2",
".",
"1",
"6",
"8",
".",
"2",
".",
"1",
"5",
"7",
".",
".",
"."
]
解决方案
它是一个数组(以 ansible 语言列出)。您正在寻找第一个元素
ip_result.ansible_facts.ip[0]
推荐阅读
- python - Python 无法获得 iotop 输出
- javascript - 将 Object.defineProperty 与 let 或 var 一起使用时会发生奇怪的事情
- swift - ModelIO/MDLAsset 是短视的吗?
- r - 在 R Shiny 中选择“全部”单选按钮选项
- r - 关于使用 R 中的概率矩阵生成遵循伯努利分布的随机数矩阵
- html - Azure 搜索:将结果导出到 CSV
- javascript - React:渲染嵌套的 json 数据时遇到问题
- apache - 为挂载到容器的卷数据设置权限?
- python - lxml:如何知道命名空间前缀使用哪个命名空间?
- stm32 - 我可以得到简单的代码来发送数据到液晶显示器 我可以得到简单的代码来发送数据到液晶显示器吗