---
- hosts: masters
  gather_facts: no
  become: true
  tasks:
  - name: Get controller ID in all masters
    shell: |
      journalctl -b -u atomic-openshift-master-controllers.service --output cat | grep "Attempting to acquire controller lease as" | tail -1 | awk '{ print $11 }' | sed 's/,//'
    changed_when: False
    register: masterid

  - name: Get etcd lease
    shell: |
      source /etc/profile.d/etcdctl.sh &&
      etcdctl2 get /openshift.io/leases/controllers
    changed_when: False
    register: controllerid
    delegate_to: "{{ groups.masters.0 }}"
    run_once: True

  - debug: msg="Controller running in {{ inventory_hostname }}"
    when: 'controllerid.stdout ==  masterid.stdout'
