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

时间:2018-08-22 11:05:23

标签: ansible zenity

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

2 个答案:

答案 0 :(得分: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
    ...

答案 1 :(得分:0)

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

---
- hosts: targets

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

脚本是这样的。

#!/bin/bash
DISPLAY=:0 zenity --warning