---
- hosts: admin2
gather_facts: false
sudo: yes
tasks:
- nagios: action=downtime minutes=20 author="Dimitri Yioulos" service=host host={{item}}
with_items: "{{ groups['sqlservers'] }}"
delegate_to: admin2
tags:
- nagios_downtime
- nagios: action=downtime minutes=20 author="Dimitri Yioulos" service=all host={{item}}
with_items: "{{ groups['sqlservers'] }}"
delegate_to: admin2
tags:
- nagios_downtime
- hosts: sqlservers
gather_facts: false
tasks:
- name: copy logoff script to servers
win_copy: src=/etc/ansible/files/Logoff-Users.ps1 dest='c:\temp\Logoff-Users.ps1'
tags:
- copy_script
- name: log off users
raw: '@powershell c:\temp\Logoff-Users.ps1'
tags:
- userlogoff
- name: win update
win_updates:
category: ['SecurityUpdates','CriticalUpdates','Updates','Tools','DefinitionUpdates','UpdateRollups']
register: reboot_hint
tags:
- update
- hosts: lyris
gather_facts: false
tasks:
- name: check for Lyris service
raw: sc query ListManager
register: lyris_hint
failed_when: lyris_hint.rc not in [0,1060] # 1060 == Service not installed
tags:
- lyris_stop
- name: stop Lyris services
win_service: name={{ item }} state=stopped start_mode=manual
with_items: ["ListManager", "LyrisAlert"]
when: lyris_hint.rc == 0 # ie, the ListManager service is installed
tags:
- lyris_stop
- name: kill LyrisConsole process
raw: taskill /f /im LyrisConsole.exe
tags:
- lyris_stop
- hosts: sqlservers
gather_facts: false
tasks:
- name: reboot server
raw: 'cmd /c shutdown /r /t 0'
when: reboot_hint.reboot_required == true
As you can see, there are several things going on here: put servers in downtime in Nagios; put a remote user logout script on the servers, run the script, then apply Windows updates; stop a particular service, and stop a small program, on another set of servers (must be done; I'll skip the explanation) and, finally; reboot the servers if the installed updates require same. Some of this is based on answers to previous questions I've posted (thanks, all, so much). I'm not sure if it's the cleanest, or most elegant, way to do all of that stuff, but the playbook does work. At the end of the day, that's what counts.
Dimitri