Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta flush_handlers doesn't work in role #79023

Closed
1 task done
twouters opened this issue Oct 4, 2022 · 3 comments · Fixed by #79057
Closed
1 task done

meta flush_handlers doesn't work in role #79023

twouters opened this issue Oct 4, 2022 · 3 comments · Fixed by #79057
Assignees
Labels
affects_2.14 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. P2 Priority 2 - Issue Blocks Release verified This issue has been verified/reproduced by maintainer

Comments

@twouters
Copy link
Contributor

twouters commented Oct 4, 2022

Summary

Triggering handlers with ansible.builtin.meta: flush_handlers in a role results in an error

Issue Type

Bug Report

Component Name

meta

Ansible Version

$ ansible --version
ansible [core 2.14.0b2]
  config file = /home/twouters/.ansible.cfg
  configured module search path = ['/home/twouters/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/twouters/ansible-2.14/lib/python3.10/site-packages/ansible
  ansible collection location = /home/twouters/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/twouters/ansible-2.14/bin/ansible
  python version = 3.10.7 (main, Sep  6 2022, 21:22:27) [GCC 12.2.0] (/home/twouters/ansible-2.14/bin/python)
  jinja version = 3.1.2
  libyaml = True

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all

OS / Environment

Arch Linux and Debian but probably irrelevant

Steps to Reproduce

$ tree -Ap                   
[drwx------]  .
├── [drwxr-xr-x]  testrole
│   ├── [drwxr-xr-x]  handlers
│   │   └── [-rw-r--r--]  main.yml
│   └── [drwxr-xr-x]  tasks
│       └── [-rw-r--r--]  main.yml
└── [-rw-r--r--]  test.yml

3 directories, 3 files
$ cat test.yml 
- hosts: localhost
  pre_tasks:
    - ansible.builtin.command: /bin/true
      notify: do nothing
  handlers:
    - name: do nothing
      ansible.builtin.debug:
        msg: hello
  roles:
    - testrole
$ cat testrole/tasks/main.yml    
---

- ansible.builtin.command: /bin/true
  notify: noop

- ansible.builtin.meta: flush_handlers

- ansible.builtin.command: /bin/true
$ cat testrole/handlers/main.yml 
---

- name: noop
  ansible.builtin.debug:
    msg: world

Expected Results

I expect the play to succeed and trigger the handler

$ ansible-playbook test.yml -l localhost
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost
does not match 'all'

PLAY [localhost] ***************************************************************************************

TASK [Gathering Facts] *********************************************************************************
ok: [localhost]

TASK [ansible.builtin.command] *************************************************************************
changed: [localhost]

RUNNING HANDLER [do nothing] ***************************************************************************
ok: [localhost] => {
    "msg": "hello"
}

TASK [testrole : ansible.builtin.command] **************************************************************
changed: [localhost]

TASK [testrole : ansible.builtin.meta] *****************************************************************

RUNNING HANDLER [testrole : noop] **********************************************************************
ok: [localhost] => {
    "msg": "world"
}

TASK [testrole : ansible.builtin.command] **************************************************************
changed: [localhost]

PLAY RECAP *********************************************************************************************
localhost                  : ok=6    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Actual Results

$ ansible-playbook test.yml -l localhost           [WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost
does not match 'all'

PLAY [localhost] ***************************************************************************************

TASK [Gathering Facts] *********************************************************************************
ok: [localhost]

TASK [ansible.builtin.command] *************************************************************************
changed: [localhost]

RUNNING HANDLER [do nothing] ***************************************************************************
ok: [localhost] => {
    "msg": "hello"
}

TASK [testrole : ansible.builtin.command] **************************************************************
changed: [localhost]

TASK [testrole : ansible.builtin.meta] *****************************************************************
ERROR! BUG: There seems to be a mismatch between tasks in PlayIterator and HostStates.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented Oct 4, 2022

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.14 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Oct 4, 2022
@mkrizek
Copy link
Contributor

mkrizek commented Oct 4, 2022

Thanks for the report.

The following is likely the fix:

diff --git a/lib/ansible/plugins/strategy/linear.py b/lib/ansible/plugins/strategy/linear.py
index a9406a20748..a268b0b39cc 100644
--- a/lib/ansible/plugins/strategy/linear.py
+++ b/lib/ansible/plugins/strategy/linear.py
@@ -42,6 +42,7 @@ from ansible.plugins.loader import action_loader
 from ansible.plugins.strategy import StrategyBase
 from ansible.template import Templar
 from ansible.utils.display import Display
+from ansible.utils.fqcn import add_internal_fqcns

 display = Display()

@@ -118,7 +119,7 @@ class StrategyModule(StrategyBase):
         # once hosts synchronize on 'flush_handlers' lockstep enters
         # '_in_handlers' phase where handlers are run instead of tasks
         # until at least one host is in IteratingStates.HANDLERS
-        if (not self._in_handlers and cur_task.action == 'meta' and
+        if (not self._in_handlers and cur_task.action in add_internal_fqcns(('meta',)) and
                 cur_task.args.get('_raw_params') == 'flush_handlers'):
             self._in_handlers = True

I will work on making the diff into a PR, until then meta: can be used instead of ansible.builtin.meta: as a workaround.

@mkrizek mkrizek self-assigned this Oct 4, 2022
@mkrizek mkrizek added the verified This issue has been verified/reproduced by maintainer label Oct 4, 2022
@sivel sivel added P2 Priority 2 - Issue Blocks Release and removed needs_triage Needs a first human triage before being processed. labels Oct 5, 2022
@sivel
Copy link
Member

sivel commented Oct 5, 2022

Instead of directly using add_internal_fqcns in the strategy we can use C._ACTION_META which is already defined.

mkrizek added a commit to mkrizek/ansible that referenced this issue Oct 6, 2022
@ansibot ansibot added the has_pr This issue has an associated PR. label Oct 6, 2022
bcoca pushed a commit that referenced this issue Oct 6, 2022
mkrizek added a commit to mkrizek/ansible that referenced this issue Oct 6, 2022
sivel pushed a commit that referenced this issue Oct 6, 2022
@ansible ansible locked and limited conversation to collaborators Oct 13, 2022
kosalaat pushed a commit to kosalaat/ansible that referenced this issue Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.14 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. P2 Priority 2 - Issue Blocks Release verified This issue has been verified/reproduced by maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants