Block of include_tasks with handler/notify

1,634 views
Skip to first unread message

Stefan Engel

unread,
Jun 22, 2021, 12:57:03 AM6/22/21
to Ansible Project
Hi,

Im trying to achieve the following:
  • creating a block with multiple include tasks 
  • If any of the tasks change, write the config and sync to HA device (F5)

    tasks:
  - name: F5 Vanity VIP update in all DC's 
    block:
    - name: Update SSL profile
      include_tasks: tasks/vanity/f5_ssl_profile_update.yml
    - name: Update irule
      include_tasks: tasks/vanity/f5_irule_update.yml
notify: 
  - Save sys config
  - Sync configuration from device to group
  handlers:
  - name: Save sys config
  - name: Sync configuration from device to group

I'm getting the following error:
ERROR! 'notify' is not a valid attribute for a Block

In the Ansible doc, I couldnt find a clear statement that notify isnt supported within a Block. 

Appreciate your feedback.

Vladimir Botka

unread,
Jun 22, 2021, 2:10:05 AM6/22/21
to Stefan Engel, ansible...@googlegroups.com
On Mon, 21 Jun 2021 21:57:03 -0700 (PDT)
Stefan Engel <bkke...@gmail.com> wrote:

> I'm getting the following error:
> *ERROR! 'notify' is not a valid attribute for a Block*
>
> In the Ansible doc, I couldnt find a clear statement that notify isnt
> supported within a Block.

See "Playbook Keywords". In 2.9, only task can notify a handler
https://docs.ansible.com/ansible/2.9/reference_appendices/playbooks_keywords.html

"latest" shows both task and block can notify a handler
https://docs.ansible.com/ansible/latest/reference_appendices/playbooks_keywords.html

Works for me in 2.10

- hosts: localhost
tasks:
- block:
- command: 'true'
changed_when: true
notify: test
handlers:
- name: test
debug:
msg: Handler test running.

gives

ok: [localhost] =>
msg: Handler test running.

--
Vladimir Botka

Vladimir Botka

unread,
Jun 22, 2021, 2:12:30 AM6/22/21
to Stefan Engel, ansible...@googlegroups.com
On Mon, 21 Jun 2021 21:57:03 -0700 (PDT)
Stefan Engel <bkke...@gmail.com> wrote:

> I'm getting the following error:
> *ERROR! 'notify' is not a valid attribute for a Block*
>
> In the Ansible doc, I couldnt find a clear statement that notify isnt
> supported within a Block.

shell> grep -r notify /scratch/ansible-release-notes/ | grep block
/scratch/ansible-release-notes/CHANGELOG-v2.11.rst:- notify keyword
is not ignored anymore on import_tasks, also able to apply to blocks
now.

--
Vladimir Botka

Stefan Engel

unread,
Jun 22, 2021, 4:00:14 AM6/22/21
to Ansible Project
Thanks Vladimir! I'll upgrade to 2.11.x core and give it another try
Reply all
Reply to author
Forward
0 new messages