ansible: ansible_ssh_user Overriding values for hosts in a group
<p>i am having one inventory file which contains different login info for multiple hosts.But while calling the ansible_ssh_user value in playbook i am getting only last entry.</p>

<p>Why it takes the last entry ansible_ssh_user ?</p>

<p>Inventory File:</p>

<pre><code>[local]
10.41.42.2 ansible_ssh_user=root ansible_ssh_pass=root123

[DSC_root]
10.41.42.2  ansible_ssh_user=root ansible_ssh_pass=root123
10.41.42.70 ansible_ssh_user=root ansible_ssh_pass=root
10.41.42.71 ansible_ssh_user=root ansible_ssh_pass=root

[DSC_admin]
10.41.42.2  ansible_ssh_user=root ansible_ssh_pass=root123
10.41.42.70 ansible_ssh_user=dscadmin ansible_ssh_pass=dscadmin
10.41.42.71 ansible_ssh_user=dscadmin ansible_ssh_pass=dscadmin
</code></pre>

<p>Playbook:</p>

<pre><code>---
- hosts: DSC_root 
  remote_user: root
  tasks:
- name: get root user home grep and register
  shell: &gt;
         grep "^{{ansible_ssh_user}}:" /etc/passwd | awk -F: '{ print $6 }'
  changed_when: false
  register: v_getuserhome
- debug: var=v_getuserhome
</code></pre>

<p>Logs:</p>

<pre><code>    [root@mavosdsc ansible]# ansible-playbook -i inventory1 get_home.yml

    PLAY [DSC_root] ****************************************************************

    TASK [setup] *******************************************************************
    ok: [10.41.42.71]
    ok: [10.41.42.70]
    ok: [10.41.42.2]

    TASK [get root user home grep and register] ************************************
    ok: [10.41.42.70]
    ok: [10.41.42.71]
    ok: [10.41.42.2]

    TASK [debug] *******************************************************************
    ok: [10.41.42.70] =&gt; {
        "v_getuserhome": {
            "changed": false, 
            "cmd": "grep \"^dscadmin:\" /etc/passwd | awk -F: '{ print $6 }'", 
            "delta": "0:00:00.005985", 
            "end": "2016-07-31 09:23:42.743393", 
            "rc": 0, 
            "start": "2016-07-31 09:23:42.737408", 
            "stderr": "", 
            "stdout": "/home/dscadmin", 
            "stdout_lines": [
                "/home/dscadmin"
            ], 
            "warnings": []
        }
    }
    ok: [10.41.42.2] =&gt; {
        "v_getuserhome": {
            "changed": false, 
            "cmd": "grep \"^root:\" /etc/passwd | awk -F: '{ print $6 }'", 
            "delta": "0:00:00.005801", 
            "end": "2016-07-31 18:53:44.074155", 
            "rc": 0, 
            "start": "2016-07-31 18:53:44.068354", 
            "stderr": "", 
            "stdout": "/root", 
            "stdout_lines": [
                "/root"
            ], 
            "warnings": []
        }
    }
    ok: [10.41.42.71] =&gt; {
        "v_getuserhome": {
            "changed": false, 
            "cmd": "grep \"^dscadmin:\" /etc/passwd | awk -F: '{ print $6 }'", 
            "delta": "0:00:00.006740", 
            "end": "2016-07-31 09:23:43.347801", 
            "rc": 0, 
            "start": "2016-07-31 09:23:43.341061", 
            "stderr": "", 
            "stdout": "/home/dscadmin", 
            "stdout_lines": [
                "/home/dscadmin"
            ], 
            "warnings": []
        }
    }

    PLAY RECAP *********************************************************************
    10.41.42.2                : ok=3    changed=0    unreachable=0    failed=0   
    10.41.42.70               : ok=3    changed=0    unreachable=0    failed=0   
    10.41.42.71               : ok=3    changed=0    unreachable=0    failed=0   
</code></pre>