I would suggest considering using ansible for this purpose. Here is a simple playbook that collects some data on the nodes specified in the inventory file and adds it to the local file:
- hosts: all remote_user: your_user tasks: - name: collect load average shell: cat /proc/loadavg register: cluster_node_la - name: write to local disk lineinfile: dest=/tmp/cluster_stat create=yes line="{{ ansible_fqdn }}:{{ cluster_node_la.stdout_lines }}" delegate_to: 127.0.0.1
You can run it like this: ansible-playbook -i ansible-inventory stats-playbook.yml --forks=1
- ansible_inventory is a file containing a list of your hosts
- stats-playbook.yml is the file printed above
Of course, depending on how you are going to store the collected data, this may be implemented differently, but I think the general idea is clear. Anyway, there are many ways to solve this problem in ansible .
In addition, ansible has a python API, and you can do most things directly from python! Ie, here's how we can build your cluster configuration:
import pprint import ansible.runner import ansible.inventory inventory_file = 'ansible_inventory'
source share