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

handlers not fired when using roles #83172

Closed
Mapel88 opened this issue May 1, 2024 · 8 comments
Closed

handlers not fired when using roles #83172

Mapel88 opened this issue May 1, 2024 · 8 comments
Labels
affects_2.14 affects_2.15 bug This issue/PR relates to a bug. needs_info This issue requires further information. Please answer any outstanding questions.

Comments

@Mapel88
Copy link

Mapel88 commented May 1, 2024

Summary

I have a role with handlers, but they doesn't seem to fire on change.

The files were changed but there is no indication for handlers being executed and the services were not restarted:

image

image

Am i missing something?
Do I need to include the handlers anywhere?
According to the documentation handlers should be included automatically from handlers/main.yaml.. so not sure what's the issue..

Issue Type

Bug Report

Component Name

ansible handlers

Ansible Version

$ ansible --version
ansible [core 2.15.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.2 (main, Oct 13 2023, 04:53:37) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18.0.6)] (/usr/bin/python3.11)
  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

Red Hat Enterprise Linux release 8.8 (Ootpa)

Steps to Reproduce

role/handlers/main.yaml:

- name: restart salt-master
  become: true
  service: 
    name: salt-master 
    state: restarted

- name: restart salt-minion
  become: true
  service: 
    name: salt-minion 
    state: restarted

role/tasks/main.yaml

- name: Setup saltmaster
  include_tasks: saltmaster/salt.yaml

role/tasks/saltmaster/salt.yaml

- name: Set auto_accept to False in /etc/salt/master
  ansible.builtin.lineinfile:
    path: /etc/salt/master
    search_string: '#auto_accept: False'
    line: 'auto_accept: False'
    owner: root
    group: root
    mode: '0640'
  notify: restart salt-master

- name: Edit the salt configuration on the minion and add the Master
  shell: |
    printf "master: {{ ansible_hostname }}.{{ my_domain }}\n" > /etc/salt/minion.d/99-master-address.conf
    printf "$(hostname)\n" > /etc/salt/minion_id
  notify: restart salt-minion

I also tried the following syntax for handlers which also doesn't work:

- name: restart saltmaster
  service: name=salt-master state=restarted

- name: restart salt-minion
  service: name=salt-minion state=restarted

my playbook:

- hosts: some-server
  become: true
  vars_files:
    - "{{ playbook_dir }}/../vars.yaml"
  vars:
    env: "{{ ansible_local['local']['env'] }}"
    
  roles:
     - salt

Expected Results

expected services salt-minion and salt-master to be restarted

Actual Results

TASK [salt : Set auto_accept to True in /etc/salt/master] *********************************************************************************************************************************************************
changed: [some server]

TASK [salt : Set target_env based on hostname] ********************************************************************************************************************************************************************
ok: [some-server]


TASK [salt : Edit the salt configuration on the minion and add the Master] ****************************************************************************************************************************************
changed: [some-server]

TASK [salt : Pause for 1 minute to make sure minion is registered] ************************************************************************************************************************************************
Pausing for 60 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
ok: [some-server]


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct
@ansibot ansibot added bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. affects_2.14 labels May 1, 2024
@ansibot
Copy link
Contributor

ansibot commented May 1, 2024

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.

@ansibot
Copy link
Contributor

ansibot commented May 1, 2024

@Mapel88 ansible-core 2.14 is not supported and no longer receives bug fixes. Please test against one of the supported versions of ansible-core, preferably the most recent one, to see whether the bug has been fixed.

click here for bot help

@Mapel88
Copy link
Author

Mapel88 commented May 1, 2024

upgraded to 2.15.3 - issue persists

@s-hertel
Copy link
Contributor

s-hertel commented May 1, 2024

By default the handlers should run after the roles: section is done, but you can execute notified handlers early by using a - meta: flush_handlers task: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_handlers.html#controlling-when-handlers-run.

@Mapel88
Copy link
Author

Mapel88 commented May 2, 2024

They should also should run when using "notify", but they don't...
and they also didn't run when roles was done.
didn't try to use flush_handlers, might work, but it doesn't solve the issue for not running when notified. if it works it might do well as a workaround but not a solution.

@mkrizek
Copy link
Contributor

mkrizek commented May 2, 2024

Please provide a minimal self-contained reproducer that we can copy&paste, run and see the issue you are describing. The provided reproducer appears to be doing unrelated things and does not seem to be complete. Without that there is nothing we can do here outside of guessing.

@mkrizek mkrizek added the needs_info This issue requires further information. Please answer any outstanding questions. label May 2, 2024
@mkrizek
Copy link
Contributor

mkrizek commented May 2, 2024

They should also should run when using "notify", but they don't...

Yes but not immediately. See the link to documentation @s-hertel posted.

@Mapel88
Copy link
Author

Mapel88 commented May 2, 2024

ok then i misunderstood the usage. i thought notify will immediately trigger the handler. thanks for clarifying.
closing this ticket.

@Mapel88 Mapel88 closed this as completed May 2, 2024
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.14 affects_2.15 bug This issue/PR relates to a bug. needs_info This issue requires further information. Please answer any outstanding questions.
Projects
None yet
Development

No branches or pull requests

5 participants