Collecting Remote Cluster Information Using Ansible
Use Ansible to automatically deploy and run the Kunpeng Health Inspector tool. Then use the tool to collect server hardware data and download reports. If you have server O&M experience, try this example.
Prerequisites
- Ansible 2.9 or later has been installed on the server.
- SSH key authentication is enabled on the target server.
- The Kunpeng Health Inspector tool package (devkit-kspect-x.x.x-Linux-aarch64.tar.gz) is ready.
- The target server is a Kunpeng server and supports SSH access.
Collecting Basic Hardware Information
- Create a directory.
1mkdir -p /home/kspect-ansible/{group_vars,files,templates}
- Save the Kunpeng Health Inspector tool package into the /home/kspect-ansible/files/ directory.
1cp /path/to/devkit-kspect-x.x.x-Linux-aarch64.tar.gz /home/kspect-ansible/files/
- Switch to the /home/kspect-ansible directory.
1cd /home/kspect-ansible
- Create and complete the host inventory file inventory.ini.
1vi inventory.ini
- If BMC information is not collected, you do not need to enter the BMC user name or password.
- The server password and BMC password are stored in the inventory file in plaintext. You are advised to use Ansible Vault to encrypt the passwords.
- You are advised to periodically change the BMC account password.
Press i to enter the insert mode.
[servers] server1 ansible_host=xxx.xxx.xxx.xxx ansible_user=root server2 ansible_host=xxx.xxx.xxx.xxx ansible_user=root bmc_ip=xxx.xxx.xxx.xxx bmc_user=Administrator bmc_password=xxxx [servers:vars] kspect_package=devkit-kspect-x.x.x-Linux-aarch64.tar.gz kspect_dir=devkit-kspect-x.x.x-Linux-aarch64 install_dir=/tmp/kspect_collect
Press Esc, type :wq!, and press Enter to save the file and exit.
- Create and complete the collection script files kspect_no_bmc.exp and kspect_with_bmc.exp.
- BMC information is not collected.
1vi templates/kspect_no_bmc.expPress i to enter the insert mode.
#!/usr/bin/expect -f set timeout 1800 ; spawn ./kspect -l 0 all expect { "Are you sure you want to enter (y/N)" { send "N\r" exp_continue } eof { exit 0 } timeout { send_user "timeout" exit 1 } }Press Esc, type :wq!, and press Enter to save the file and exit.
- BMC information is collected.
1vi templates/kspect_with_bmc.expPress i to enter the insert mode.
#!/usr/bin/expect -f set timeout 1800 set bmc_ip [lindex $argv 0] set bmc_user [lindex $argv 1] set bmc_password [lindex $argv 2] set timeout 1800 ; spawn ./kspect -l 0 all expect { "Are you sure you want to enter (y/N)" { send "y\r" exp_continue } "BMC IP address:" { send "$bmc_ip\r" exp_continue } "Username:" { send "$bmc_user\r" exp_continue } "Password:" { send "$bmc_password\r" exp_continue } "BMC manager dump? (y/N)" { send "N\r" exp_continue } eof { exit 0 } timeout { send_user "timeout" exit 1 } }Press Esc, type :wq!, and press Enter to save the file and exit.
- BMC information is not collected.
- Create and complete the main playbook configuration file kspect_collect.yml.
1vi kspect_collect.ymlPress i to enter the insert mode.
- name: Remote data collection. hosts: servers gather_facts: yes become: yes tasks: - name: Check the architecture of the target server. fail: msg: "This tool supports only Kunpeng servers." when: ansible_architecture != "aarch64" - name: Create an installation directory. file: path: "{{ install_dir }}" state: directory mode: '0700' - name: Upload the Kunpeng Health Inspector package. copy: src: "files/{{ kspect_package }}" dest: "{{ install_dir }}/{{ kspect_package }}" mode: '0600' - name: Extract the Kunpeng Health Inspector package. unarchive: src: "{{ install_dir }}/{{ kspect_package }}" dest: "{{ install_dir }}" copy: no mode: '0700' - name: Search for the directory generated after the Kunpeng Health Inspector package is extracted. find: paths: "{{ install_dir }}" patterns: "kspect*,devkit*" file_type: directory register: kspect_dirs - name: Set the Kunpeng Health Inspector directory variable. set_fact: kspect_dir: "{{ kspect_dirs.files[0].path | basename }}" when: kspect_dirs.files | length > 0 - name: Display the Kunpeng Health Inspector directory. debug: var: kspect_dir - name: Check whether BMC information is configured. set_fact: has_bmc_info: "{{ bmc_ip is defined and bmc_ip | length > 0 }}" - name: Display the BMC configuration status. debug: msg: "{{ 'BMC information is configured. BMC data will be collected.' If has_bmc_info else ' BMC information is not configured. BMC data will be skipped.' }}" - name: Create an Expect interaction script. template: src: "{{ 'kspect_with_bmc.exp' if has_bmc_info else 'kspect_no_bmc.exp' }}" dest: "{{ install_dir }}/{{ kspect_dir }}/run_kspect.exp" mode: '0700' - name: Check whether the output directory exists. stat: path: "{{ install_dir }}/{{ kspect_dir }}/output" register: output_dir - name: Create an output directory (if the directory does not exist). file: path: "{{ install_dir }}/{{ kspect_dir }}/output" state: directory mode: '0700' when: not output_dir.stat.exists - name: Run the Kunpeng Health Inspector to collect data. shell: | cd "{{ install_dir }}/{{ kspect_dir }}" {{ 'expect run_kspect.exp "' ~ bmc_ip ~ '" "' ~ bmc_user ~ '" "' ~ bmc_password ~ '"' if has_bmc_info else './kspect -s all' }} args: executable: /bin/bash environment: TERM: xterm async: 1200 poll: 30 register: kspect_job - name: Wait until collection is complete. async_status: jid: "{{ kspect_job.ansible_job_id }}" register: kspect_result until: kspect_result.finished retries: 30 delay: 10 - name: Check the Kunpeng Health Inspector running status. debug: var: kspect_result - name: Check whether a report file exists. shell: | ls -la "{{ install_dir }}/{{ kspect_dir }}/output/" || echo "Directory does not exist." find "{{ install_dir }}/{{ kspect_dir }}/output" -name "*.tar.gz" -type f 2>/dev/null || echo "No report file found." register: direct_file_check - name: Display the file check result. debug: var: direct_file_check.stdout - name: Search for a report file. shell: | find "{{ install_dir }}/{{ kspect_dir }}/output" -name "kspect-report-*.tar.gz" -type f register: shell_find_files - name: Display the search result. debug: var: shell_find_files.stdout_lines - name: Set the report file path. set_fact: report_file_path: "{{ shell_find_files.stdout_lines[0] }}" when: shell_find_files.stdout_lines | length > 0 - name: Verify the report file. stat: path: "{{ report_file_path }}" register: report_stat when: report_file_path is defined - name: Display the report file status. debug: var: report_stat when: report_file_path is defined - name: Create a local report directory. delegate_to: localhost run_once: yes file: path: "reports/{{ inventory_hostname }}" state: directory - name: Download the collection report. fetch: src: "{{ report_file_path }}" dest: "reports/{{ inventory_hostname }}/" flat: yes when: report_file_path is defined and report_stat.stat.exists - name: Check whether the report has been downloaded. delegate_to: localhost stat: path: "reports/{{ inventory_hostname }}/{{ (report_file_path | basename) }}" register: downloaded_report ignore_errors: yes when: report_file_path is defined - name: Display the download result. debug: msg: "Report download status: {{ downloaded_report.stat.exists if downloaded_report is defined else 'Unknown' }}" when: report_file_path is defined - name: Clear remote files. file: path: "{{ install_dir }}" state: absent - name: Verify the clearance result. shell: | if [ -d "{{ install_dir }}" ]; then echo "The directory still exists." exit 1 else echo "The directory has been deleted." exit 0 fi register: cleanup_check failed_when: cleanup_check.stdout == "The directory still exists." ignore_errors: yes - name: Display the collection result of each server. debug: msg: "{{ s }}" vars: s: >- {% if (downloaded_report.stat.exists | default(false)) %} Data of server {{ inventory_hostname }} is successfully collected and the report is saved in reports/{{ inventory_hostname }}/{{ (report_file_path | basename) }}. {% else %} Data of server {{ inventory_hostname }} failed to be collected. {% endif %}Press Esc, type :wq!, and press Enter to save the file and exit.
- Start a collection task.
1ansible-playbook -i inventory.ini kspect_collect.yml
The command output displays the directory for saving the collected report package.
- View the directory for storing the report file.View the file directory structure to check the path for storing the collected compressed package.
1tree /home/kspect-ansibleA collection report is saved in the reports directory. The command output is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13
kspect-ansible/ ├── inventory.ini ├── kspect_collect.yml ├── templates/ │ ├── kspect_with_bmc.exp │ └── kspect_no_bmc.exp ├── reports │ └── server1 │ └── kspect-report-2025xxxx-xxxxx1.tar.gz │ └── server2 │ └── kspect-report-2025xxxx-xxxxx2.tar.gz └── files/ └── devkit-kspect-x.x.x-Linux-aarch64.tar.gz
- Extract the report package.
1 2 3
cd /home/kspect-ansible/reports/server1 tar -zxvf kspect-report-xxxxxxxx-xxxxxx.tar.gz cd kspect-report-xxxxxxxx-xxxxxx
The collection report package contains the full information file (HTML/JSON/CSV) and dmesg log file. You can use a browser to view the HTML file and use the kspect tool to view the JSON file.
- Copy the result file to the report directory.
1cp -r kspect-report-xxxxxxxx-xxxxxx /home/devkit-kspect-x.x.x-Linux-aarch64/output
- Use the kspect tool to view the report.
You can use the -h option to view the report SN.
1 2
cd /home/devkit-kspect-x.x.x-Linux-aarch64 ./kspect report -h
Command output:
1 2 3 4 5 6 7 8
... ... -r REPORT, --report REPORT Indicates the report to be displayed. (You can also enter the report path. Tool collection reports and reported generated using diff/diff_x86 are supported. 1: /home/devkit-kspect-x.x.x-Linux-aarch64/output/kspect-report-20251119-105559/kspect-json-20251119-105559.json <2025-11-19 10:55:59> 2: /home/devkit-kspect-x.x.x-Linux-aarch64/output/kspect-report-20251119-105135/kspect-json-20251119-105135.json <2025-11-19 10:54:01> ... ...
Use the -r option to view the specified report.
1./kspect report -r 1
Figure 1 Report content
- Compare reports of different servers.
1./kspect report -d 1,2
Figure 2 Storage information
In the comparison report, the data items whose difference exceeds the threshold (20% by default) are marked in red. The different hardware and software configurations are also marked in red to facilitate subsequent operations such as unified configuration.