是否可以通过Ansible在前台运行脚本

问题描述 投票:0回答:2

我使用Ansible将某些内容推送到节点,我想使用Zenity来警告正在使用节点的用户我正在做什么,但我无法弄清楚如何在节点前景上运行脚本显示。可以通过Ansible运行脚本,但是在节点而不是控制机器上显示它?

ansible zenity
2个回答
0
投票

您可以使用this answer了解如何使用notify-send通知用户。我建议写一个专用的脚本,你可以将消息作为参数传递,而不是将内联放在ansible中

所以你可以做到

- hosts: targets
  tasks:

  - name: Notify of imminent upgrade
    shell: "/opt/myscripts/notify-connected-users Upgrade and reboot coming soon"

  - name: Let give some time to users to read the message
    pause:
      minutes: 1

  - name: continue the operation
    ...

0
投票

我发现我需要做的就是使用脚本模块在节点上运行我的本地脚本。

---
- hosts: targets

  tasks:   
  - name: Notify of imminent upgrade
    script: /home/hero/loading.sh

脚本是这样的。

#!/bin/bash
DISPLAY=:0 zenity --warning
© www.soinside.com 2019 - 2024. All rights reserved.