如何从ansible解析输出

时间:2018-11-02 05:57:23

标签: 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", 
        ".", 
        ".", 
        "."
    ]

1 个答案:

答案 0 :(得分:0)

这是一个数组(以多种语言列出)。您正在寻找第一个元素

ip_result.ansible_facts.ip[0]
相关问题