selective tasks in playbook

34 views
Skip to first unread message

shloco

unread,
May 15, 2023, 12:30:36 PM5/15/23
to Ansible Project

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

shloco

unread,
May 15, 2023, 12:44:15 PM5/15/23
to Ansible Project

- 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
           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
           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:

Kosala Atapattu

unread,
May 16, 2023, 12:30:23 AM5/16/23
to ansible...@googlegroups.com
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 some time back, which might be relevant to what you're looking for.

Kosala




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f07e30cf-ca4c-4eeb-83d4-997de9d37e1cn%40googlegroups.com.

Kosala Atapattu

unread,
May 16, 2023, 9:00:30 PM5/16/23
to ansible...@googlegroups.com
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 :).

Kosala



Reply all
Reply to author
Forward
0 new messages