gpt4 book ai didi

Ansible 处理程序和 shell 模块

转载 作者:行者123 更新时间:2023-12-03 09:13:16 25 4
gpt4 key购买 nike

我有一个剧本,其中包含以下任务和处理程序部分(只是一个片段):

  tasks:
- name: 'Run legacy script and power off'
debug: msg="Preparing for reboot"
notify: Legacy sysprep

handlers:
- name: Enable Service1
service: name=service1 enabled=yes state=restarted

- name: Legacy sysprep
shell: /var/scripts/prep-reboot.sh

当我运行 playbook 时,我看到调用 Legacy sysprep 处理程序的任务的调试消息,并且看到 Enable Service1 处理程序已执行,但 Legacy sysprep 处理程序不会被调用(它不会出现在剧本输出中,也不会在系统上运行)并且服务器不会重新启动(脚本的一部分)。

是的,我计划将 prep-reboot.sh 脚本迁移到 Ansible playbook,但令我惊讶的是 shell 模块似乎不起作用?还是我忽略了一个错误?使用 -vvv 运行不会报告任何意外情况。

Ansible 和 Ansible-playbook 版本 2.1.1.0 在 RHEL 6.8 上运行。

最佳答案

谢谢你,@techraf,你为我指明了正确的方向。我最终将 changed_when: true 添加到调试行,并强制播放注册更改,然后触发相应的处理程序。

这是我的实际测试剧本供引用:

---
- name: Testing forced handler
hosts: testsys_only
gather_facts: True

tasks:
- name: 'Run legacy script and power off'
debug: msg="Preparing for reboot"
changed_when: true
notify: Legacy sysprep

handlers:
- name: Enable Service1
service: name=service1 enabled=yes state=restarted

- name: Legacy sysprep
shell: /var/scripts/prep-reboot.sh

关于Ansible 处理程序和 shell 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39881178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com