<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">ansible 1.5.4</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">RHEL 5/6</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">When copying files to NFS, they fail with the following error:</p>
<p dir="auto">failed: [myhost] =&gt; {"cur_context": ["system_u", "object_r", "nfs_t", "s0"], "failed": true, "gid": 0, "group": "root", "input_was": ["system_u", "object_r", "usr_t", "s0"], "md5sum": "mymd5sum", "mode": "0644", "new_context": ["system_u", "object_r", "usr_t", "s0"], "owner": "root", "path": "/my/nfs/mount", "secontext": "system_u:object_r:nfs_t:s0", "size": 1234, "state": "file", "uid": 0}<br>
msg: invalid selinux context</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">Use copy module to copy a file to an nfs mount.</p>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">The file is copied to the nfs mount.</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">Error message from above:</p>
<p dir="auto">failed: [myhost] =&gt; {"cur_context": ["system_u", "object_r", "nfs_t", "s0"], "failed": true, "gid": 0, "group": "root", "input_was": ["system_u", "object_r", "usr_t", "s0"], "md5sum": "mymd5sum", "mode": "0644", "new_context": ["system_u", "object_r", "usr_t", "s0"], "owner": "root", "path": "/my/nfs/mount", "secontext": "system_u:object_r:nfs_t:s0", "size": 1234, "state": "file", "uid": 0}<br>
msg: invalid selinux context</p>
<p dir="auto">I just ran into issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="25656385" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/5632" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/5632/hovercard" href="https://github.com/ansible/ansible/issues/5632">#5632</a> - "invalid selinux context" with template over ZFS and NFS. The "fix" there was to add better debugging output, but that wasn't really a fix because it's still failing. the core of the issue seems to be that one cannot change context on NFS mounts (for the most part). Ansible should check for contexts of “nfs_t”, and not bother trying to change context if that's the case. I worked around this by forcing the context of the entire mount to the context ansible was trying to set, but that's not a great workaround because if ansible decides to set different contexts based on the files I'm copying over, one or the other will fail. Note I have selinux set to permissive, so the problem is not with selinux (per se).</p>
<p dir="auto">There are a few potential fixes:</p>
<ul dir="auto">
<li>have some way of allowing users to control the selinux context in the playbook/copy module. this would then let me override ansible and force the "nfs_t" context when copying to nfs. Not great as a user experience because I have to track when/if I'm copying to nfs, but better than nothing. Worth noting this use case in the docs if this is indeed the appropriate fix as it wouldn't be obvious from the error message.</li>
<li>detecting if a file is destined for a nfs mount, and if so, skip the attempt to change selinux context. this seems to be the approach that puppet took, from my googling: <a href="http://projects.puppetlabs.com/issues/1681" rel="nofollow">http://projects.puppetlabs.com/issues/1681</a></li>
</ul>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">handlers listen</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2.2"><pre class="notranslate"><code class="notranslate">2.2
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">While writing test for handlers listen, I found inconsistencies in how handlers are marked for execution:</p>
<p dir="auto">If handlers listen, it is not necessarily a must that they require a name (as we notify the listen param), if the task notifies two or more handlers having the same module (here set_fact) only one handler will be executed:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  handlers:
    - set_fact:
      notify_listen_ran_1: True
      listen: notify_listen

    - set_fact:
        notify_listen_ran_2: True
      listen: notify_listen"><pre class="notranslate">  <span class="pl-ent">handlers</span>:
    - <span class="pl-ent">set_fact</span>:
      <span class="pl-ent">notify_listen_ran_1</span>: <span class="pl-c1">True</span>
      <span class="pl-ent">listen</span>: <span class="pl-s">notify_listen</span>

    - <span class="pl-ent">set_fact</span>:
        <span class="pl-ent">notify_listen_ran_2</span>: <span class="pl-c1">True</span>
      <span class="pl-ent">listen</span>: <span class="pl-s">notify_listen</span></pre></div>
<p dir="auto">Because ansible uses the "module/plugin" name (<a href="https://github.com/ansible/ansible/blob/devel/lib/ansible/playbook/task.py#L120">https://github.com/ansible/ansible/blob/devel/lib/ansible/playbook/task.py#L120</a> and <a href="https://github.com/ansible/ansible/blob/devel/lib/ansible/executor/task_queue_manager.py#L150">https://github.com/ansible/ansible/blob/devel/lib/ansible/executor/task_queue_manager.py#L150</a>), only the first handler will be executed.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: test handlers listen
  hosts: localhost
  gather_facts: false
  connection: local
  pre_tasks:
    - name: notify some handlers
      command: echo foo
      notify:
        - notify_listen
  tasks:
    - meta: flush_handlers

    - name: assert all defined handlers ran without error
      assert:
        that:
        - &quot;notify_listen_ran_1 is defined&quot;
        - &quot;notify_listen_ran_2 is defined&quot;

  handlers:
    - set_fact:
        notify_listen_ran_1: True
      listen: notify_listen

    - set_fact:
        notify_listen_ran_2: True
      listen: notify_listen"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">test handlers listen</span>
  <span class="pl-ent">hosts</span>: <span class="pl-s">localhost</span>
  <span class="pl-ent">gather_facts</span>: <span class="pl-c1">false</span>
  <span class="pl-ent">connection</span>: <span class="pl-s">local</span>
  <span class="pl-ent">pre_tasks</span>:
    - <span class="pl-ent">name</span>: <span class="pl-s">notify some handlers</span>
      <span class="pl-ent">command</span>: <span class="pl-s">echo foo</span>
      <span class="pl-ent">notify</span>:
        - <span class="pl-s">notify_listen</span>
  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">meta</span>: <span class="pl-s">flush_handlers</span>

    - <span class="pl-ent">name</span>: <span class="pl-s">assert all defined handlers ran without error</span>
      <span class="pl-ent">assert</span>:
        <span class="pl-ent">that</span>:
        - <span class="pl-s"><span class="pl-pds">"</span>notify_listen_ran_1 is defined<span class="pl-pds">"</span></span>
        - <span class="pl-s"><span class="pl-pds">"</span>notify_listen_ran_2 is defined<span class="pl-pds">"</span></span>

  <span class="pl-ent">handlers</span>:
    - <span class="pl-ent">set_fact</span>:
        <span class="pl-ent">notify_listen_ran_1</span>: <span class="pl-c1">True</span>
      <span class="pl-ent">listen</span>: <span class="pl-s">notify_listen</span>

    - <span class="pl-ent">set_fact</span>:
        <span class="pl-ent">notify_listen_ran_2</span>: <span class="pl-c1">True</span>
      <span class="pl-ent">listen</span>: <span class="pl-s">notify_listen</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">My suggestion is, that we enforce to have a handler name specified. So Ansible should fail for handlers without a name.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="No config file found; using defaults
 [WARNING]: Host file not found: /etc/ansible/hosts

 [WARNING]: provided hosts list is empty, only localhost is available


PLAYBOOK: test_handlers_listen2.yml ********************************************
1 plays in test_handlers_listen2.yml

PLAY [test handlers listen] ****************************************************

TASK [notify some handlers] ****************************************************
task path: /home/resmo/Projects/resmo/ansible/test/integration/test_handlers_listen2.yml:6
NOTIFIED HANDLER set_fact
changed: [localhost] =&gt; {&quot;changed&quot;: true, &quot;cmd&quot;: [&quot;echo&quot;, &quot;foo&quot;], &quot;delta&quot;: &quot;0:00:00.002432&quot;, &quot;end&quot;: &quot;2016-10-01 08:47:41.952511&quot;, &quot;rc&quot;: 0, &quot;start&quot;: &quot;2016-10-01 08:47:41.950079&quot;, &quot;stderr&quot;: &quot;&quot;, &quot;stdout&quot;: &quot;foo&quot;, &quot;stdout_lines&quot;: [&quot;foo&quot;], &quot;warnings&quot;: []}

RUNNING HANDLER [set_fact] *****************************************************
ok: [localhost] =&gt; {&quot;ansible_facts&quot;: {&quot;notify_listen_ran_1&quot;: true}, &quot;changed&quot;: false}

TASK [assert all defined handlers ran without error] ***************************
task path: /home/resmo/Projects/resmo/ansible/test/integration/test_handlers_listen2.yml:13
fatal: [localhost]: FAILED! =&gt; {
    &quot;assertion&quot;: &quot;notify_listen_ran_2 is defined&quot;, 
    &quot;changed&quot;: false, 
    &quot;evaluated_to&quot;: false, 
    &quot;failed&quot;: true
}
    to retry, use: --limit @/home/resmo/Projects/resmo/ansible/test/integration/test_handlers_listen2.retry

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=1  "><pre class="notranslate"><code class="notranslate">No config file found; using defaults
 [WARNING]: Host file not found: /etc/ansible/hosts

 [WARNING]: provided hosts list is empty, only localhost is available


PLAYBOOK: test_handlers_listen2.yml ********************************************
1 plays in test_handlers_listen2.yml

PLAY [test handlers listen] ****************************************************

TASK [notify some handlers] ****************************************************
task path: /home/resmo/Projects/resmo/ansible/test/integration/test_handlers_listen2.yml:6
NOTIFIED HANDLER set_fact
changed: [localhost] =&gt; {"changed": true, "cmd": ["echo", "foo"], "delta": "0:00:00.002432", "end": "2016-10-01 08:47:41.952511", "rc": 0, "start": "2016-10-01 08:47:41.950079", "stderr": "", "stdout": "foo", "stdout_lines": ["foo"], "warnings": []}

RUNNING HANDLER [set_fact] *****************************************************
ok: [localhost] =&gt; {"ansible_facts": {"notify_listen_ran_1": true}, "changed": false}

TASK [assert all defined handlers ran without error] ***************************
task path: /home/resmo/Projects/resmo/ansible/test/integration/test_handlers_listen2.yml:13
fatal: [localhost]: FAILED! =&gt; {
    "assertion": "notify_listen_ran_2 is defined", 
    "changed": false, 
    "evaluated_to": false, 
    "failed": true
}
    to retry, use: --limit @/home/resmo/Projects/resmo/ansible/test/integration/test_handlers_listen2.retry

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=1  
</code></pre></div>