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

4
我是一名有用的助手,可以为您翻译文本。

我遇到了一个之前没有遇到过的问题。我在CI环境中运行Ansible 2.7.6。我的主机是从Packer和VirtualBox创建的云镜像上的Windows 10 OpenStack。到目前为止,它一直工作得很好。我引入了第二个任务,想要通知我的重启处理程序,结果现在我得到了多次重启。

这是我的play和tasks,为了可读性而进行了清理。为了实现win_shell的幂等性所需的错误处理不太美观:

- 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)的任务?还是应该在一个游戏中的所有通知仅触发一次处理程序?

1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接