Ansible playbook shell output

后端 未结 7 1168
长发绾君心
长发绾君心 2020-12-23 09:27

I would like to quickly monitor some hosts using commands like ps,dstat etc using ansible-playbook. The ansible command itself perfectly does what I want, for i

7条回答
  •  借酒劲吻你
    2020-12-23 09:34

    I found using the minimal stdout_callback with ansible-playbook gave similar output to using ad-hoc ansible.

    In your ansible.cfg (Note that I'm on OS X so modify the callback_plugins path to suit your install)

    stdout_callback     = minimal
    callback_plugins    = /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/plugins/callback
    

    So that a ansible-playbook task like yours

    ---
    -
      hosts: example
      gather_facts: no
      tasks:
        - shell: ps -eo pcpu,user,args | sort -r -k1 | head -n5
    

    Gives output like this, like an ad-hoc command would

    example | SUCCESS | rc=0 >>
    %CPU USER     COMMAND
     0.2 root     sshd: root@pts/3
     0.1 root     /usr/sbin/CROND -n
     0.0 root     [xfs-reclaim/vda]
     0.0 root     [xfs_mru_cache]
    

    I'm using ansible-playbook 2.2.1.0

提交回复
热议问题