Me too new just from my scenario I am suggesting to use a handler on play book level.
And then added a notify to handler on each task where I expect a reboot to be done.
Below is a trial run we did.
.
├── README.md
├── ansible.cfg
├── group_vars
│ ├── all
│ ├── ccenter.yml
│ ├── linux.yml
│ └── windows.yml
├── handlers
│ └── main.yml
├── hosts
├── roles
│ ├── oc
│ │ └── tasks
│ │ └── main.yml
│ ├── todo
│ │ ├── files
│ │ │ └── temp_files
│ │ │ ├── 1.txt
│ │ │ ├── 2.txt
│ │ │ └── dummy
│ │ │ └── dummy.txt
│ │ └── tasks
│ │ └── main.yml
│ └── trial
│ ├── files
│ │ └── sample.xml
│ ├── meta
│ │ └── main.yml
│ └── tasks
│ ├── RedHat.yml
│ ├── Windows.yml
│ └── main.yml
├── site.retry
└── site.yml
handler/main.yml
- name: Reboot windows server
win_reboot:
msg: Reboot initiated by Ansible
test_command: whoami
register: win_reboot_result
sample task in the playbook
- name: Install Web Deploy 3.6
win_package:
name: Microsoft Web Deploy 3.6
product_id: '{6773A61D-755B-4F74-95CC-97920E45E696}'
arguments: '/q /norestart'
state: present
expected_return_code: [0, 666, 3010]
notify:
- Reboot windows server
- name: force all notified handlers to run at this point, not waiting for normal sync points
meta: flush_handlers
Note: Reboot will be done if any change identified on that task.
Thanks,
Sivakumar