# selective tasks in playbook

**URL:** <https://forum.ansible.com/t/selective-tasks-in-playbook/37985>\
**Category:** Ansible Project\
**Tags:** awx\
**Created:** [May 15, 2023, 4:30pm UTC](https://forum.ansible.com/t/selective-tasks-in-playbook/37985 "2023-05-15T16:30:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shloco](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@shloco](https://forum.ansible.com/u/shloco)\
**Post date:** [May 15, 2023, 4:30pm UTC](https://forum.ansible.com/t/selective-tasks-in-playbook/37985/1 "2023-05-15T16:30:35Z")

</div>

I’m looking for a way to run the tasks that inside the block by node by node but in other hand I need to send email once in the beginning and end of the activity - after all nodes were reboot

in my code example email was sent for each node the tasks are exec

note: I run the playbook via AWX

![Screen Shot 2023-05-15 at 16.47.12.png]()

---

<div class="post-metadata">

**Author:** ![shloco](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@shloco](https://forum.ansible.com/u/shloco)\
**Post date:** [May 15, 2023, 4:44pm UTC](https://forum.ansible.com/t/selective-tasks-in-playbook/37985/2 "2023-05-15T16:44:15Z")

</div>

- name : restart app  
hosts: webserver  
serial: 1  
tasks:
- name: send email activity start  
mail:

block:

- name: Task 1

- name: Task 2 - reboot node  
reboot:

- name: check node is up and running  
uri:  
url: [http://SomeURL](http://SomeURL)  
method: GET  
status\_code: 200  
register: \_result  
until: (\_result.status == 200)  
retries: 720 # 720 \* 5 seconds = 1hour (60\*60/5)  
delay: 5 # Every 5 seconds

- name: send email activity completed  
run\_once: true  
mail:

- name : restart app  
hosts: DBserver  
serial: 1  
tasks:

- name: send email activity start  
run\_once: true  
mail:

block:

- name: Task 1

- name: Task 2 - reboot node

- name: check node is up and running  
uri:  
url: [http://SomeURL](http://SomeURL)  
method: GET  
status\_code: 200  
register: \_result  
until: (\_result.status == 200)  
retries: 720 # 720 \* 5 seconds = 1hour (60\*60/5)  
delay: 5 # Every 5 seconds

- name: send email activity completed  
run\_once: true  
mail:

---

<div class="post-metadata">

**Author:** ![Kosala\_Atapattu1](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kosala\_Atapattu1](https://forum.ansible.com/u/Kosala_Atapattu1)\
**Post date:** [May 16, 2023, 4:29am UTC](https://forum.ansible.com/t/selective-tasks-in-playbook/37985/3 "2023-05-16T04:29:56Z")

</div>

serial might not be the best option for your case. I’d consider using throttle, and consider using free strategy, so each server which reboots are checked immediately.

I’d use the throttle on the block level.

I wrote [this](https://medium.com/@kosala.atapattu/understanding-ansible-strategy-de8f95013ff4) some time back, which might be relevant to what you’re looking for.

---

<div class="post-metadata">

**Author:** ![Kosala\_Atapattu1](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kosala\_Atapattu1](https://forum.ansible.com/u/Kosala_Atapattu1)\
**Post date:** [May 17, 2023, 1:00am UTC](https://forum.ansible.com/t/selective-tasks-in-playbook/37985/4 "2023-05-17T01:00:02Z")

</div>

Come to think of it, the reason you’re trying to throttle is to manage each reboot and check individually, rt?.. actually free strategy will allow you to do that, in a parallel queue. If I may be presumptuous, free strategy might be the thing you’re after in your case :).
