【问题标题】:Is it possible to run script in foreground via Ansible是否可以通过 Ansible 在前台运行脚本
【发布时间】:2018-08-22 11:05:23
【问题描述】:

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

【问题讨论】:

  • 我不明白你为什么说“在后台”。 ansible 的设计目的是在节点(称为目标)上执行比控制机器更多的任务。请阅读帮助部分How to Ask 并澄清问题(按钮edit)。
  • @baptistemm 我从来没有说过“在后台”
  • 对不起,我的意思是“在前台”

标签: ansible zenity


【解决方案1】:

您可以使用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
    ...

【讨论】:

  • 这仍然显示在我的终端上,我想为不适合我的用户显示一些对话框。
  • 我提到的脚本应该向所有用户发送通知。
【解决方案2】:

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

---
- hosts: targets

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

脚本是这样的。

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

【讨论】:

    猜你喜欢
    • 2016-05-10
    • 2011-01-15
    • 2017-03-29
    • 2020-02-03
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多