It's less a technical question, but maybe Ansible has features that would help, here, that I don't know yet. I'm able to automate patching with Ansible, but choosing the right hosts/groups in the right order is complicated, I'll try to explain it.
Lets take this inventory for example:
---
all:
  dcs:
    hosts:
      domaincontroller1
      domaincontroller2
  dbs:
    hosts:
      sql1
      sql2
  webservers:
    hosts:
      websrv1 #has a mysql connection and services vars
      websrv2
      websrv3 #has a mysql connection and services vars
      websrv4
So what you do on a patch day? You want that at least one domain controller is running every time. You want that all webservers that connect to sql are down, or their services are stopped, after that you first patch the sql servers, wait until they are running again, patch the web servers and wait until they connect to sql.
At the moment, I split the host file into two groups. First group is one DC and all servers that don't connect to sql. The second group contains sql1, sql2, webserver1, ... and there is a different playbook that patches the first 2 in the row first, and all other after that. But when doing this, I have an ugly/unsorted hosts file and I'm unable to apply changes to all web servers for example.
---
all:
  patch1:
    hosts:
      domaincontroller1
      websrv2
      websrv4
  patch2:
    hosts:
      sql1
      sql2
      domaincontroller2
      websrv1 #has a mysql connection and services vars
      websrv3 #has a mysql connection and services vars
How others do that? Is there a way to split groups in half, so there is a patch1 group that contains 50% of the DCs and all web servers where no services are defined (probably with dynamic groups?). Otherwise I would need to create the perfect grouped inventory and add groups for patch day 1 and 2 underneath it, which results in having one server multiple times in the same inventory what makes changes more complicated.
Another idea would be the use of tags, like patchfirst, patchsecond, and create for any server a host_vars file which is again pretty much work for about 100 hosts. Anyone ideas or examples how to get the best looking, best working result without making more work as manual patching would need?
 
    