Ansible处理程序在播放结束时运行两次

问题描述 投票:3回答:1

我有一个以前从未见过的问题。我在CI环境中运行Ansible 2.7.6。我的主机是我使用Packer和VirtualBox创建的云映像在OpenStack上安装的Windows 10。到目前为止,一切正常。我在很多任务中引入了第二项任务,我想通知我的重启处理程序,现在我得到了多次重启。

这是我的剧本和任务,为了易于阅读而进行了一些清理。使用win_shell aint pretty来实现幂等性所需的错误处理:

- hosts: workstations
  tasks:

   ...

    - name: Enable Windows feature
      include_role: name=win-config tasks_from=feature

    - name: Install language pack
      include_role: name=win-config tasks_from=language-pack

   ...

tasks/feature.yml

- name: Inspect feature
  win_shell: DISM /Online /Get-FeatureInfo /FeatureName:Microsoft-Hyper-V
  register: check

- name: Enable Windows feature
  win_shell: DISM /Online /Enable-Feature /All /FeatureName:Microsft-Hyper-V /NoRestart
  notify: Reboot
  when: '"Disabled" in check.stdout_lines[12]'

tasks/language-pack.yml

- name: Check language pack
  win_shell: |
    Get-WindowsPackage -Online `
                       -PackagePath 'C:\Programdata\cab\Microsoft-Windows-Client-Language-Pack_x64_sv-se.cab' `
                       | Select-Object `
                       -ExpandProperty PackageState
  register: check

- name: Install language pack
  win_shell: |
    Add-WindowsPackage -Online `
                       -PackagePath 'C:\Programdata\cab\Microsoft-Windows-Client-Language-Pack_x64_sv-se.cab' `
                       -NoRestart
  when: '"Installed" not in check.stdout'
  notify: Reboot

handlers/main.yml

- name: Reboot
  win_reboot:
    post_reboot_delay: 60

结果:

tasks run with status `changed` and the end of play unfolds...
...
RUNNING HANDLER [win-config : Reboot] ******************************************
Sunday 20 October 2019  18:48:55 +0200 (0:00:00.057)       0:46:55.167 ******** 
changed: [node1.example.com]

RUNNING HANDLER [win-config : Reboot] ******************************************
Sunday 20 October 2019  18:51:11 +0200 (0:02:16.527)       0:49:11.695 ******** 
fatal: [node1.example.com]: FAILED! => {
    "changed": false,
    "reboot": false
}

MSG:

The WS-Management service cannot process the request because the request contained invalid selectors for the resource.  (extended fault data: {'transport_message': 'Bad HTTP response returned from server. Code 500', 'http_status_code': 500, 'wsmanfault_code': '2150858843', 'fault_code': 's:Sender', 'fault_subcode': 'w:InvalidSelectors'})


NO MORE HOSTS LEFT *************************************************************

PLAY RECAP *********************************************************************
...

我被认为相信,除非需要,否则处理程序的自动刷新应该只触发每个处理程序一次,即使在播放过程中被通知了更多次。

有人看到过这种行为吗?我还有第二个角色,与处理程序同名。我的第一个想法是Ansible也以某种方式调用了该处理程序,但是排除其他角色,或者重命名处理程序并没有为我解决。

处理人员可以对所谓的任何事情保持挑剔吗?来自特定文件的任务,例如task/main.yml?还是应该只一次播放一次来自所有通知的触发处理程序?

windows ansible handler
1个回答
0
投票

看来您正在遇到以下问题中描述的行为:

https://github.com/ansible/ansible/issues/47374

这里似乎对此主题进行了热烈的讨论:

https://github.com/ansible/ansible/pull/53644

我不清楚在后续的Ansible版本中是否已解决此问题。

© www.soinside.com 2019 - 2024. All rights reserved.