<p dir="auto"><strong>Issue Type</strong><br>
Bug Report</p>
<p dir="auto"><strong>Ansible Version</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible --version
ansible 2.1.0 (devel c44110bc81) last updated 2016/01/26 14:25:38 (GMT +200)
  lib/ansible/modules/core: (detached HEAD 33014c6db1) last updated 2016/01/11 10:48:27 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 82a4cf84be) last updated 2016/01/11 10:48:30 (GMT +200)
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

  Distribution:    Debian GNU/Linux 8.2 (jessie)"><pre class="notranslate"><code class="notranslate">$ ansible --version
ansible 2.1.0 (devel c44110bc81) last updated 2016/01/26 14:25:38 (GMT +200)
  lib/ansible/modules/core: (detached HEAD 33014c6db1) last updated 2016/01/11 10:48:27 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 82a4cf84be) last updated 2016/01/11 10:48:30 (GMT +200)
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

  Distribution:    Debian GNU/Linux 8.2 (jessie)
</code></pre></div>
<p dir="auto"><strong>Ansible Configuration</strong><br>
gathering = explicit<br>
pipelining = True</p>
<p dir="auto"><strong>Summary</strong><br>
When assigning tags to roles, tags are not overwritten.</p>
<p dir="auto"><strong>Steps To Reproduce</strong><br>
Here the tree :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="├── mydep
│   ├── meta
│   │   └── main.yml
│   └── tasks
│       └── main.yml
├── myrole
│   ├── meta
│   │   └── main.yml
│   └── tasks
│       └── main.yml
└── playbook.yml"><pre class="notranslate"><code class="notranslate">├── mydep
│   ├── meta
│   │   └── main.yml
│   └── tasks
│       └── main.yml
├── myrole
│   ├── meta
│   │   └── main.yml
│   └── tasks
│       └── main.yml
└── playbook.yml
</code></pre></div>
<p dir="auto">File <strong>playbook.yml</strong> :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: localhost
  roles:
    - { role : myrole , tags : 'role1', var : 'one' }
    - { role : myrole , tags : 'role2', var : 'two' }
    - { role : myrole , var : 'three' }"><pre class="notranslate"><code class="notranslate">- hosts: localhost
  roles:
    - { role : myrole , tags : 'role1', var : 'one' }
    - { role : myrole , tags : 'role2', var : 'two' }
    - { role : myrole , var : 'three' }
</code></pre></div>
<p dir="auto">File <strong>myrole/tasks/main.yml</strong> and <strong>mydep/tasks/main.yml</strong> :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- name: Debug
  debug: msg=&quot;{{ var }}&quot;"><pre class="notranslate"><code class="notranslate">
---
- name: Debug
  debug: msg="{{ var }}"
</code></pre></div>
<p dir="auto">File <strong>myrole/meta/main.yml</strong> :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
allow_duplicates: yes
dependencies:
  - { role : mydep }"><pre class="notranslate"><code class="notranslate">
---
allow_duplicates: yes
dependencies:
  - { role : mydep }
</code></pre></div>
<p dir="auto"><strong>Expected Results</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook playbook.yml --list-tasks --list-tags 

playbook: playbook.yml

  play #1 (localhost):  TAGS: []
    tasks:
      mydep : Debug     TAGS: [role1]
      myrole : Debug    TAGS: [role1]
      mydep : Debug     TAGS: [role2]
      myrole : Debug    TAGS: [role2]
      mydep : Debug     TAGS: []
      myrole : Debug    TAGS: []
      TASK TAGS: [role1, role2]"><pre class="notranslate"><code class="notranslate">$ ansible-playbook playbook.yml --list-tasks --list-tags 

playbook: playbook.yml

  play #1 (localhost):  TAGS: []
    tasks:
      mydep : Debug     TAGS: [role1]
      myrole : Debug    TAGS: [role1]
      mydep : Debug     TAGS: [role2]
      myrole : Debug    TAGS: [role2]
      mydep : Debug     TAGS: []
      myrole : Debug    TAGS: []
      TASK TAGS: [role1, role2]
</code></pre></div>
<p dir="auto"><strong>Actual Results</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook playbook.yml --list-tasks --list-tags 

playbook: playbook.yml

  play #1 (localhost):  TAGS: []
    tasks:
      mydep : Debug     TAGS: [role1]
      myrole : Debug    TAGS: [role1]
      mydep : Debug     TAGS: [role1, role2]
      myrole : Debug    TAGS: [role2]
      mydep : Debug     TAGS: [role1]
      myrole : Debug    TAGS: []
      TASK TAGS: [role1, role2]"><pre class="notranslate"><code class="notranslate">$ ansible-playbook playbook.yml --list-tasks --list-tags 

playbook: playbook.yml

  play #1 (localhost):  TAGS: []
    tasks:
      mydep : Debug     TAGS: [role1]
      myrole : Debug    TAGS: [role1]
      mydep : Debug     TAGS: [role1, role2]
      myrole : Debug    TAGS: [role2]
      mydep : Debug     TAGS: [role1]
      myrole : Debug    TAGS: []
      TASK TAGS: [role1, role2]
</code></pre></div>
<p dir="auto">Sylvain</p>
<ul dir="auto">
<li>using ansible from devel branch (<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/7812c70d3b8a8fbab3127ee7033345a0fb455bfe/hovercard" href="https://github.com/ansible/ansible/commit/7812c70d3b8a8fbab3127ee7033345a0fb455bfe"><tt>7812c70</tt></a>)</li>
<li>having custom name "some-machine" for a host in hosts file</li>
<li>and exact ip as ansible_ssh_host in corresponding host_vars/some-machine</li>
</ul>
<p dir="auto">for ex. copy action fails on:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [some-machine] =&gt; Traceback (most recent call last):
  File &quot;/home/psedlak/all/src/ansible/lib/ansible/runner/__init__.py&quot;, line 583, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File &quot;/home/psedlak/all/src/ansible/lib/ansible/runner/__init__.py&quot;, line 757, in _executor_internal
    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
  File &quot;/home/psedlak/all/src/ansible/lib/ansible/runner/__init__.py&quot;, line 990, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File &quot;/home/psedlak/all/src/ansible/lib/ansible/runner/action_plugins/copy.py&quot;, line 179, in run
    remote_checksum = self.runner._remote_checksum(conn, tmp_path, dest_file)
  File &quot;/home/psedlak/all/src/ansible/lib/ansible/runner/__init__.py&quot;, line 1167, in _remote_checksum
    inject = self.get_inject_vars(conn.host)
  File &quot;/home/psedlak/all/src/ansible/lib/ansible/runner/__init__.py&quot;, line 607, in get_inject_vars
    host_variables = self.inventory.get_variables(host, vault_password=self.vault_pass)
  File &quot;/home/psedlak/all/src/ansible/lib/ansible/inventory/__init__.py&quot;, line 443, in get_variables
    raise Exception(&quot;host not found: %s&quot; % hostname)
Exception: host not found: 10.10.10.1"><pre class="notranslate"><code class="notranslate">fatal: [some-machine] =&gt; Traceback (most recent call last):
  File "/home/psedlak/all/src/ansible/lib/ansible/runner/__init__.py", line 583, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/home/psedlak/all/src/ansible/lib/ansible/runner/__init__.py", line 757, in _executor_internal
    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
  File "/home/psedlak/all/src/ansible/lib/ansible/runner/__init__.py", line 990, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File "/home/psedlak/all/src/ansible/lib/ansible/runner/action_plugins/copy.py", line 179, in run
    remote_checksum = self.runner._remote_checksum(conn, tmp_path, dest_file)
  File "/home/psedlak/all/src/ansible/lib/ansible/runner/__init__.py", line 1167, in _remote_checksum
    inject = self.get_inject_vars(conn.host)
  File "/home/psedlak/all/src/ansible/lib/ansible/runner/__init__.py", line 607, in get_inject_vars
    host_variables = self.inventory.get_variables(host, vault_password=self.vault_pass)
  File "/home/psedlak/all/src/ansible/lib/ansible/inventory/__init__.py", line 443, in get_variables
    raise Exception("host not found: %s" % hostname)
Exception: host not found: 10.10.10.1
</code></pre></div>
<p dir="auto">My guess after quickly looking into the code is that:</p>
<ul dir="auto">
<li><em>copy.run</em> calls _runner.<em>remote_checksum</em> (btw calling (single) underscore method from outside?) passing conn (it does not have hostname avail)</li>
<li><em><em>remote_checksum</em> uses <em>inventory.get</em>...</em> which expects <em>hostname</em> but from <em>conn</em> object it gets "just" <em>ip</em> to where connection was initialized</li>
<li>that results in not finding <em>ip</em> value in the <em>inventory</em> (_hosts_cache there has <em>hostnames</em> as keys)</li>
</ul>
<p dir="auto">I'm not sure what should be correct behaviour where here. Have inventory use ip's for lookup/caching? There seems to be also conn.delegate which holds the hostname so maybe using that value (if it exists, otherwise continue with .host as it is atm)?</p>
<p dir="auto">I didn't checked but it seems this was "introduced" (as side effect) by change <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/f1267c0b053e5975dc08c151530c802015902242/hovercard" href="https://github.com/ansible/ansible/commit/f1267c0b053e5975dc08c151530c802015902242"><tt>f1267c0</tt></a> "Move from md5 to sha1..." when remote_md5 was changed to remote_checksum and instead of doing plain conn.shell.md5 it started consulting HostVars etc, and based on the size of the change I assume it may impact also assemble, fetch, template and unarchive actions.</p>