我必须检查目标虚拟机的/ etc / hosts文件。如果该文件中有任何以10。。。*开头的ip。它应报告是并显示ip,如果没有ip,则应在该目标主机名下报告No。所有这些信息都应该在天青管道中构建工件。.请向我建议可能性
file
查找实际上是IMO的一个很好的开始。我在下面遵循的想法是:- hosts: localhost
gather_facts: false
tasks:
- name: Read /etc/hosts file in a list line by line
set_fact:
my_host_entries: "{{ lookup('file', '/etc/hosts').split('\n') }}"
- name: Add matching ips to a list
vars:
ip_regex: "^10(\\.\\d+){3}"
set_fact:
matching_ips: "{{ matching_ips | default([]) + [item | regex_search(ip_regex)] }}"
when: item is match(ip_regex)
loop: "{{ my_host_entries }}"
- name: Show list of matching ips
debug:
var: matching_ips
when: matching_ips | default([]) | length > 0
您可以适应您的确切需求。