title: Ansible first hostname of groups
body: <p>I am not sure on how to find the first ansible hostname from group_names. Could you kindly advise me on how to do it?</p>
  
  <p>hosts</p>
  
  <pre><code>[webservers]
  server1
  server2
  server3
  
  [webserver-el7]
  server4
  server5
  server6
  </code></pre>
  
  <p>And i have 2 different playbook for each host groups</p>
  
  <p>playbook1.yml</p>
  
  <pre><code>- name: deploy app
    hosts: webservers
    serial: 8
    roles:
      - roles1
  </code></pre>
  
  <p>playbook2.yml</p>
  
  <pre><code>- name: deploy app
    hosts: webservers-el7
    serial: 8
    roles:
      - roles1
  </code></pre>
  
  <p>the problem is that i have delegate task to first host of each group. previously i only used webservers group, so it was much easier by using the task below</p>
  
  <pre><code>- name: syncing web files to {{ version_dir }}
    synchronize:
      src: "{{ build_dir }}"
      dest: "{{ version_dir }}"
      rsync_timeout: 60
    delegate_to: "{{ groups.webservers | first }}"
  </code></pre>
  
  <p>If i have 2 different group_names, how can i select the first one of each group? so it can be more dynamic</p>