<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ansible core (ssh login)</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.0.0
  config file = ... /ansible/etc/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.6.6 (r266:84292, Aug 18 2016, 08:36:59) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]"><pre class="notranslate"><code class="notranslate">ansible 2.3.0.0
  config file = ... /ansible/etc/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.6.6 (r266:84292, Aug 18 2016, 08:36:59) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">new install from tar ball</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When a host file contains the same host under multiple groupings the final ansible_user setting overrides and the  ansible_user=xxx is ignored from the actual host entry being used.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">Create an inventory file</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[bobs-machines]
machineA  ansible_user=bob
machineB  ansible_user=bob

[sallys-machines]
machineA ansible_user=sally
machineC ansible_user=sally
"><pre class="notranslate"><code class="notranslate">[bobs-machines]
machineA  ansible_user=bob
machineB  ansible_user=bob

[sallys-machines]
machineA ansible_user=sally
machineC ansible_user=sally

</code></pre></div>
<p dir="auto">validate the user that ansible is using</p>
<p dir="auto">ansible -vvv <strong>bob</strong>s-machine -m ping</p>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">I would expect that both machineA and machineB are used with ssh user bob.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ESTABLISH SSH CONNECTION FOR USER: sally
ESTABLISH SSH CONNECTION FOR USER: bob
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=sally -o ConnectTimeout=10 ...
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=bob -o ConnectTimeout=10 ..."><pre class="notranslate"><code class="notranslate">ESTABLISH SSH CONNECTION FOR USER: sally
ESTABLISH SSH CONNECTION FOR USER: bob
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=sally -o ConnectTimeout=10 ...
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=bob -o ConnectTimeout=10 ...
</code></pre></div>
<p dir="auto">`<br>
If the command was run with ALL to run against all hosts, I'm not sure what I would expect the correct bahavior to be.  There are two possbility of either running against each host once using one or the other ansible_user settings or treating differnt users as different hosts and running against each of them.  The current behavior is to run against each host exaclty 1 time regardelss of ansbile_user settings and use the last ansbile_user specificed.</p>
<p dir="auto">In this example since the example command above is not running agianst Sally's host, the values for Sally's host should have no impact to Bob's hosts.</p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Feature Idea</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.8</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Any</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">I think it would be really nice to have some <code class="notranslate">role_name</code> available as variable in the tasks in same way as done for <code class="notranslate">role_path</code> <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/7051cdeb57d947a213803ca28a4e1a6a2f905d26/hovercard" href="https://github.com/ansible/ansible/commit/7051cdeb57d947a213803ca28a4e1a6a2f905d26"><tt>7051cde</tt></a> recently</p>
<p dir="auto">For now we have few options to let tasks know about current role name</p>
<ol dir="auto">
<li>set variable on role definition (playbook level)<br>
example</li>
</ol>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  roles:
    - { role: webserver, role_name: &quot;webserver&quot; }"><pre class="notranslate">  <span class="pl-ent">roles</span>:
    - <span class="pl-s">{ role: webserver, role_name: "webserver" }</span></pre></div>
<ol start="2" dir="auto">
<li>extract role folder name from <code class="notranslate">role_path</code> with <code class="notranslate">regex_replace</code> filter (task level)<br>
example</li>
</ol>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hipchat: msg='{{ role_path | regex_replace('^.*/(.*)$', '\\1') }} | tasks finished'
           token=&quot;{{ hipchat_token }}&quot;
           room=&quot;{{ hipchat_room }}&quot;
           color=&quot;{{ hipchat_color }}&quot;"><pre class="notranslate">- <span class="pl-ent">hipchat</span>: <span class="pl-s">msg='{{ role_path | regex_replace('^.*/(.*)$', '\\1') }} | tasks finished'</span>
           <span class="pl-s">token="{{ hipchat_token }}"</span>
           <span class="pl-s">room="{{ hipchat_room }}"</span>
           <span class="pl-s">color="{{ hipchat_color }}"</span></pre></div>
<p dir="auto">Please let me know if  we already have way to get role name in tasks</p>
<p dir="auto">Thanks in advance</p>