使用Ansible可以轻松地检查多个服务器和文件的文件检查。下面是一个示例解决方案:
[web_servers]
web1 ansible_host=192.168.1.10
web2 ansible_host=192.168.1.11
web3 ansible_host=192.168.1.12
---
- name: File Check
hosts: web_servers
gather_facts: false
tasks:
- name: Check File
stat:
path: /path/to/file.txt
register: file_stat
- name: Print File Status
debug:
msg: "File exists: {{ file_stat.stat.exists }}"
ansible-playbook -i hosts.ini file_check.yml
这将在"web_servers"组中的所有服务器上检查文件的存在性,并打印出文件的状态。
请确保替换示例代码中的服务器IP地址和文件路径为实际的服务器和文件路径。