@@ -105,6 +105,11 @@ of this exercise.
105105 ansible.windows.win_feature:
106106 name: Web-Server
107107 state: present
108+ register: win_feature
109+
110+ - name: Reboot if installing Web Server feature requires it
111+ ansible.windows.win_reboot:
112+ when: win_feature.reboot_required
108113
109114 - name: Start iis service
110115 ansible.windows.win_service:
@@ -137,8 +142,11 @@ of this exercise.
137142 state: present
138143` ` `
139144
140- * These three lines are calling the Ansible module **`win_feature`** to
141- install the IIS Web Server. [Click
145+ * These lines are calling the Ansible module **`win_feature`** to
146+ install the IIS Web Server, followed by a conditional reboot task.
147+ The `register` keyword captures the result of the feature installation,
148+ and the `win_reboot` module will only run if the installation requires
149+ a system restart. [Click
142150 here](https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_feature_module.html)
143151 to see all options for the `win_feature` module.
144152
@@ -251,6 +259,11 @@ You are ready to automate!
251259 ansible.windows.win_feature:
252260 name: Web-Server
253261 state: present
262+ register: win_feature
263+
264+ - name: Reboot if installing Web-Server feature requires it
265+ ansible.windows.win_reboot:
266+ when: win_feature.reboot_required
254267
255268 - name: Start iis service
256269 ansible.windows.win_service:
0 commit comments