Ansible在字符串中查找列表的任何成员

时间:2018-06-14 18:42:28

标签: ansible

我遇到一个问题,我只需要在uri请求的注册结果中找到IPS列表的任何成员时接受任务,该列表是动态生成的,并且大小可变,url是不同的聚合器微服务所以它需要时间才能填充(因此重试和延迟)

vars:
   ES_IPS: ["192.168.0.1","192.168.0.2","192.168.0.3"]  #dynamic (this is an example)
- name: Check if any member exists
  uri:
     url: http://localhost:8080/stuff
     method: GET 
     return_content: yes 
     status_code: 200 
  register: result
  until: any of ES_IPS in result.content <-------- (this here)
  retries: 100 
  delay: 10

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

请看那里:

https://docs.ansible.com/ansible/2.5/user_guide/playbooks_filters.html

我认为你应该使用一个playbooks过滤器。你试过了吗until: result.stdout.find("what you want") != -1

您还可以使用command模块:

- command: "grep  {{ result.content }} ..."
  with_items: "..."
  register: new_result

在Ansible中也存在子串:

when: variable1 | search("value")
when: '"value" in variable1'
when: fsm_out.stdout | regex_search(' data')