title: Ansible playbook targeting two groups
body: <p>I am writing an ansible playbook that upgrades Kubernetes version on the minions.</p>
  
  <pre><code>- name: Configure and start the Kubernetes Nodes
    hosts: kubernetes-minions
    serial: 1
    tasks:
     - name: backup K8S master files.
        shell: "{{item}}"
        with_items:
          - cp /etc/kubernetes/config /var/tmp/k8s-backup/
          - cp /etc/kubernetes/kubelet /var/tmp/k8s-backup/
     - name: cordon the minion.
        command: kubectl cordon {{ ansible_default_ipv4.interface }}
        delegate_to: kubernetes-master
     - name: Install latest version of Docker on Minion.
        yum: name=kubernetes-1.3.0-0.3.git86dc49a.el7 state=present
     - name: start the kubernetes kubelet
        service: name=kubelet state=restarted enabled=yes
     - name: start the kubernetes kube-proxy
        service: name=kube-proxy state=restarted enabled=yes
     - name: uncordon the minion.
        command: kubectl uncordon {{ ansible_default_ipv4.interface }}
        delegate_to: kubernetes-master
  </code></pre>
  
  <p>My inventory file looks like::</p>
  
  <pre><code>[kubernetes-masters]
  172.29.219.102
  
  [kubernetes-minions]
  172.29.219.105
  172.29.219.106
  172.29.219.107
  </code></pre>
  
  <p>Now I have defined the target group tp be <code>hosts: kubernetes-minions</code> where the actual <code>yum update</code> is supposed to happen but before this step is run on EACH minion, I need to cordon this nodes on the <code>kubernetes-master</code> </p>
  
  <p>Now the problem that I am having is how to tell ansible that for the step of cordon/uncordon , do it on the kubernetes-master node rather than the minion. I tried to use <code>delegate_to: kubernetes-master</code> but seems like its running the step on the minion itself.</p>
  
  <p>EDIT :: <strong>The upgrade on the minions will be done sequentially and not in parallel to minimize downtime.</strong> </p>