Issue 1:
Issue Type: Bug Report, Regression from #15713

Component Name: handlers

Ansible Version: 2.2.0.0

Environment: OS X 10.11.6

Summary: Under Ansible 2.2.0.0, Jinja variables contained in a handler name are no longer populated. Under Ansible 1.9.x and 2.1.1.0, they were populated. Here's a quick example:

Steps To Reproduce:

Write this content to playbook.yml:

---
- hosts: localhost
connection: local
vars:
appname: someapp
handlers:
# The following line, when the handler is executed, does not populate {{ appname }}
- name: restart {{ appname }}
debug:
msg: some bogus module call in handler {{ appname }}
tasks:
- name: bogus task with notify for {{ appname }}
command: ls
notify: restart {{ appname }}

Run the playbook: ansible-playbook --connection=local playbook.yml

Expected Results: In the output of the playbook run, any mention of {{ appname }} should not appear, but replaced with someapp, per the given variables.

Actual Results:

[WARNING]: Host file not found: /usr/local/etc/ansible/hosts

[WARNING]: provided hosts list is empty, only localhost is available

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

TASK [setup] *******************************************************************
ok: [localhost]

TASK [bogus task with notify for someapp] **************************************
changed: [localhost]

RUNNING HANDLER [restart {{ appname }}] ****************************************
ok: [localhost] => {
"msg": "some bogus module call in handler someapp"
}

PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0

Note that in the RUNNING HANDLER line, the Jinja template syntax is printed literally, rather than being populated with the variable that clearly exists, since it's populated elsewhere. This is a regression from 1.9.x and 2.1.1.0.

Issue 2:
ISSUE TYPE

Bug Report (same as #15713 and #14082)

COMPONENT NAME

Handlers and variable interpolation

ANSIBLE VERSION

ansible 2.3.0 (devel 9962245b92) last updated 2016/10/06 09:55:33 (GMT -400)
lib/ansible/modules/core: (detached HEAD 0ee774ff15) last updated 2016/10/06 09:55:59 (GMT -400)
lib/ansible/modules/extras: (detached HEAD 5cc72c3f06) last updated 2016/10/06 09:55:59 (GMT -400)
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

ansible-playbook 2.2.0.0 (stable-2.2 be6396d5e9) last updated 2016/10/05 17:40:02 (GMT -400)
lib/ansible/modules/core: (detached HEAD a6b8215e62) last updated 2016/10/05 17:45:10 (GMT -400)
lib/ansible/modules/extras: (detached HEAD d42975e068) last updated 2016/10/05 17:45:11 (GMT -400)
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
derek@derek-HP-EliteOne-800-G1-AiO:~$ ansible-playbook play.yaml
[WARNING]: provided hosts list is empty, only localhost is available

ansible-playbook 2.1.2.0 (stable-2.1 a7d0cc6e61) last updated 2016/10/05 17:42:07 (GMT -400)
lib/ansible/modules/core: (detached HEAD 4602021670) last updated 2016/10/05 17:43:21 (GMT -400)
lib/ansible/modules/extras: (detached HEAD d312f34d9b) last updated 2016/10/05 17:43:22 (GMT -400)
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
derek@derek-HP-EliteOne-800-G1-AiO:~$ ansible-playbook play.yaml
[WARNING]: provided hosts list is empty, only localhost is available

ansible 2.1.2.0 (detached HEAD 29f2f26278) last updated 2016/10/06 11:25:15 (GMT -400)
lib/ansible/modules/core: (detached HEAD 17ee1cfaf9) last updated 2016/10/06 11:30:32 (GMT -400)
lib/ansible/modules/extras: (detached HEAD d312f34d9b) last updated 2016/10/06 11:30:32 (GMT -400)
config file =
configured module search path = Default w/o overrides
derek@derek-HP-EliteOne-800-G1-AiO:~$ ansible-playbook --connection=local play.yaml
[WARNING]: Host file not found: /etc/ansible/hosts

ansible 2.1.1.0 (detached HEAD 780c363482) last updated 2016/10/06 11:32:54 (GMT -400)
lib/ansible/modules/core: (detached HEAD 242368e99b) last updated 2016/10/06 11:32:58 (GMT -400)
lib/ansible/modules/extras: (detached HEAD 14887a9ea8) last updated 2016/10/06 11:32:58 (GMT -400)
config file =
configured module search path = Default w/o overrides

ansible 2.0.0.2 (stable-2.0.0.1 3b5d7400de) last updated 2016/10/06 11:11:52 (GMT -400)
lib/ansible/modules/core: (detached HEAD ce6619bf5d) last updated 2016/10/06 11:11:55 (GMT -400)
lib/ansible/modules/extras: (detached HEAD 29af26884e) last updated 2016/10/06 11:11:55 (GMT -400)
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

No change.

OS / ENVIRONMENT

Ansible manager: Lubuntu 16.04.1

Ansible worker: Ubuntu Server 16.04.1

Python 2.7.12

SUMMARY

Ansible 2.1.2.0, 2.1.1.0, and branches devel, stable-2.2, stable-2.1, and stable-2.0.0.1 do not resolve variable references in handler names.

STEPS TO REPRODUCE

See #15713.

EXPECTED RESULTS

See #15713.

Ansible 2.1.0.0 produces the correct result:

derek@derek-HP-EliteOne-800-G1-AiO:~$ ansible --version
ansible 2.1.0.0 (detached HEAD b599477242) last updated 2016/10/06 11:36:36 (GMT -400)
lib/ansible/modules/core: (detached HEAD 04a871d007) last updated 2016/10/06 11:36:38 (GMT -400)
lib/ansible/modules/extras: (detached HEAD b5fa2b3416) last updated 2016/10/06 11:36:38 (GMT -400)
config file =
configured module search path = Default w/o overrides
derek@derek-HP-EliteOne-800-G1-AiO:~$ ansible-playbook --connection=local play.yaml
[WARNING]: Host file not found: /etc/ansible/hosts

[WARNING]: provided hosts list is empty, only localhost is available

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

TASK [setup] *******************************************************************
ok: [localhost]

TASK [bogus task with notify for someapp] **************************************
changed: [localhost]

RUNNING HANDLER [restart someapp] **********************************************
ok: [localhost] => {
"msg": "some bogus module call in handler someapp"
}

PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0

Ansible 2.0.2.0 on branch stable-2.0 produces the correct result:

derek@derek-HP-EliteOne-800-G1-AiO:~$ ansible --version
ansible 2.0.2.0 (stable-2.0 26078418e9) last updated 2016/10/06 11:13:05 (GMT -400)
lib/ansible/modules/core: (detached HEAD 1e68326ea6) last updated 2016/10/06 11:13:07 (GMT -400)
lib/ansible/modules/extras: (detached HEAD 4eb177e545) last updated 2016/10/06 11:13:07 (GMT -400)
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
derek@derek-HP-EliteOne-800-G1-AiO:~$ ansible-playbook --connection=local play.yaml
[WARNING]: provided hosts list is empty, only localhost is available

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

TASK [setup] *******************************************************************
ok: [localhost]

TASK [bogus task with notify for someapp] **************************************
changed: [localhost]

RUNNING HANDLER [restart someapp] **********************************************
ok: [localhost] => {
"msg": "some bogus module call in handler someapp"
}

PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0

ACTUAL RESULTS

Results for Ansible 2.1.2.0, 2.1.1.0, and branches devel, stable-2.2, stable-2.1, and stable-2.0.0.1:

[WARNING]: provided hosts list is empty, only localhost is available

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

TASK [setup] *******************************************************************
ok: [localhost]

TASK [bogus task with notify for someapp] **************************************
changed: [localhost]

RUNNING HANDLER [restart {{ appname }}] ****************************************
ok: [localhost] => {
"msg": "some bogus module call in handler someapp"
}

PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0