如何执行“动态”命令;top";使用Ansible在远程服务器上执行命令

如何执行“动态”命令;top";使用Ansible在远程服务器上执行命令,ansible,Ansible,我必须使用Ansible Playbook在远程服务器上执行“top”命令。 但是当我运行剧本时,转会没有成功 剧本: --- - name: CPU load hosts: all become: yes gather_facts: false tasks: - name: CPU load command: top register: cpu_result - debug: var: cpu_result.changed p.S.“mp

我必须使用Ansible Playbook在远程服务器上执行“top”命令。 但是当我运行剧本时,转会没有成功 剧本:

---
 - name: CPU load
  hosts: all
  become: yes
  gather_facts: false

  tasks:

 - name: CPU load
    command: top
    register: cpu_result

 - debug:
     var: cpu_result.changed

p.S.“mpstat”命令正常工作(使用cpu.result.stdout_行)

top
默认情况下以交互模式运行,并定期更新终端中显示的值。如果这就是您所说的“动态”,那么您无法使用Ansible获得此功能

相反,您可以运行它:

  • 在GNU版本的
    top
    的批处理模式下(
    top-b-n1
    ),或
  • 在其他Unix版本上以日志记录模式(
    top-l 1
    )运行