大网数据广告活动
服务器运维问答

Ansible display realtime shell stdout

· 52CE 我爱测

I want see the realtime shell stdout, instead of register ing in a variable and then display once it is completed. Example Playbook - test.yml - name: Testing RUN Shell Command hosts: localhost connection: local tasks: - name: Ru…

问题原文

原帖链接 · Veerendra K · CC BY-SA 4.0

I want see the realtime shell stdout, instead of registering in a variable and then display once it is completed.

Example Playbook - test.yml

- name: Testing RUN Shell Command
  hosts: localhost
  connection: local

  tasks:
  - name: Runnig Update
    shell: apt update

Default Output

$ ansible-playbook  test.yml 

PLAY [Testing RUN Shell Command] ******************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************
ok: [localhost]

TASK [Runnig Update] ******************************************************************************************************************
changed: [localhost]

PLAY RECAP ****************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0   

But I want to see what it is doing like when we run the apt update in terminal

$ sudo apt update
Ign:1 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:2 http://dl.google.com/linux/chrome/deb stable Release                                                                            
Hit:3 http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu bionic InRelease                                                              
Get:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                                                           
Hit:6 http://in.archive.ubuntu.com/ubuntu bionic InRelease                                                                            
Hit:7 http://ppa.launchpad.net/canonical-chromium-builds/stage/ubuntu bionic InRelease                                                
------OUTPUT REMOVED----------

I see that there is already discussion going on at github issue and look like that is not possible.

Is there any trick get the realtime stdout with help ansible Callback?

社区高分解答

原帖链接 · John Mahowald · CC BY-SA 4.0

"Real time" or "streaming" output has not been merged to Ansible yet. The original issue was closed in 2014 as not feasible. A more recent proposal has no major updates since February 2018.

This is not available for users of Ansible. It will require serious hacking, and more importantly testing, on command and callback plugins to work as proposed.


Bonus playbook review: Your example command can be done by the apt module. This has more features than calling apt command line yourself.

- name: Only run "apt-get update" if the last one is more than 3600 seconds ago
  apt:
    update_cache: yes
    cache_valid_time: 3600

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-06-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。