ansible/ansible

handlers not inheriting role parameters (become)

basictheprogram opened this issue · 1 comments

ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
$ ansible --version
ansible 2.2.0 (devel 19e00cf160) last updated 2016/09/09 11:04:47 (GMT -500)
  lib/ansible/modules/core: (detached HEAD bf5b3de83e) last updated 2016/09/09 11:04:47 (GMT -500)
  lib/ansible/modules/extras: (detached HEAD f83aa9fff3) last updated 2016/09/09 11:04:47 (GMT -500)
  config file =
  configured module search path = Default w/o overrides
CONFIGURATION
OS / ENVIRONMENT
SUMMARY

All my handlers that need to run as root are failing.

STEPS TO REPRODUCE
- hosts: all
  roles:
    - { role: grub2, become: yes }

grub2 handlers/main.yml

- name: update grub2
  command: "{{ update_grub2_command }}"
  register: r
  failed_when: r.rc != 0
  changed_when: False
  tags: grub2

RUNNING HANDLER [grub2 : update grub2] *****************************************
fatal: [testing_xenial64]: FAILED! => {"changed": false, "cmd": ["/usr/sbin/update-grub2"], "delta": "0:00:00.011241", "end": "2016-09-09 12:06:25.551493", "failed": true, "failed_when_result": true, "rc": 1, "start": "2016-09-09 12:06:25.540252", "stderr": "grub-mkconfig: You must run this as root", "stdout": "", "stdout_lines": [], "warnings": []}

Changing the handler to

- name: update grub2
  command: "{{ update_grub2_command }}"
  register: r
  failed_when: r.rc != 0
  changed_when: False
  become: yes
  tags: grub2

Fixes the problem.
EXPECTED RESULTS
ACTUAL RESULTS

Additional details in Ansible Development Google Group
https://groups.google.com/forum/#!topic/ansible-devel/utV9nR-1P84

Hi @basictheprogram, this appears to have been resolved by other inheritance-related fixes I've been working on recently. I can no longer replicate this in stable-2.2 or devel:

[jamesc@jimi 17490]$ cat test.yml 
- hosts: localhost
  gather_facts: no
  roles:
  - { name: test, become: yes }
[jamesc@jimi 17490]$ cat roles/test/tasks/main.yml 
---
# tasks file for roles/test
- debug:
  changed_when: true
  notify: the handler
[jamesc@jimi 17490]$ cat roles/test/handlers/main.yml 
---
# handlers file for roles/test
- name: the handler
  command: whoami
[jamesc@jimi 17490]$ ansible-playbook --version
ansible-playbook 2.2.0.0 (stable-2.2 debfb798dd) last updated 2016/11/11 08:10:00 (GMT -500)
  lib/ansible/modules/core: (detached HEAD 164225aa43) last updated 2016/11/11 10:31:30 (GMT -500)
  lib/ansible/modules/extras: (detached HEAD 18bb736cc2) last updated 2016/11/11 10:31:30 (GMT -500)
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible']
[jamesc@jimi 17490]$ ansible-playbook -vv test.yml 
Using /etc/ansible/ansible.cfg as config file
PLAYBOOK: test.yml *************************************************************
1 plays in test.yml
PLAY [localhost] ***************************************************************
TASK [test : debug] ************************************************************
task path: /home/jamesc/testing/17490/roles/test/tasks/main.yml:3
NOTIFIED HANDLER the handler
ok: [localhost] => {
    "msg": "Hello world!"
}
RUNNING HANDLER [test : the handler] *******************************************
changed: [localhost] => {"changed": true, "cmd": ["whoami"], "delta": "0:00:00.002354", "end": "2016-11-11 10:31:46.044595", "rc": 0, "start": "2016-11-11 10:31:46.042241", "stderr": "", "stdout": "root", "stdout_lines": ["root"], "warnings": []}
PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=2    unreachable=0    failed=0   

As such, we will go ahead and close this now. This will also be included in the 2.2.1.0 release.

If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!