<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">run_once<br>
delegate_to</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 = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]"><pre class="notranslate"><code class="notranslate">ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">Nothing notable changed.</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">N/A  (but using Ubuntu 16.0.4.2 for both)</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">I recently updated Ansible to 2.3.0.0 and several tasks that use a run_once: true with delegate_to: 127.0.0.1 are now being skipped.  I've included an example below which used to run as long as at least one host was valid (not skipped).   Now the play is skipped regardless when run_once: true.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Including the task below with one skipped host and one valid host on Ansible 2.3.0.0 results in the task being skipped altogether for me.  Changing it to run_once: false allows it to process with first host being skipped and the other triggering it.  The issue seems similar to this old (closed) issue -- <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="51703536" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/9784" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/9784/hovercard" href="https://github.com/ansible/ansible/issues/9784">#9784</a></p>
<p dir="auto">"As run_once will always target the first host in the list, if that host is supposed to skip a set of tasks (due to some condition, for instance), it will also skip any run_once tasks even though they may delegate_to other hosts which are willing to run that task."</p>

<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: Clone XXXXXXX locally for v{{ _current_version }}
  git:
    repo: 'git@somehost.somewhere.com:group/project.git'
    dest: '{{ _local_repobase }}/{{ _current_version }}'
    depth: 1
    update: yes
    version: 'v{{ _current_version }}'
  run_once: true
  delegate_to: 127.0.0.1"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">Clone XXXXXXX locally for v{{ _current_version }}</span>
  <span class="pl-ent">git</span>:
    <span class="pl-ent">repo</span>: <span class="pl-s"><span class="pl-pds">'</span>git@somehost.somewhere.com:group/project.git<span class="pl-pds">'</span></span>
    <span class="pl-ent">dest</span>: <span class="pl-s"><span class="pl-pds">'</span>{{ _local_repobase }}/{{ _current_version }}<span class="pl-pds">'</span></span>
    <span class="pl-ent">depth</span>: <span class="pl-c1">1</span>
    <span class="pl-ent">update</span>: <span class="pl-s">yes</span>
    <span class="pl-ent">version</span>: <span class="pl-s"><span class="pl-pds">'</span>v{{ _current_version }}<span class="pl-pds">'</span></span>
  <span class="pl-ent">run_once</span>: <span class="pl-c1">true</span>
  <span class="pl-ent">delegate_to</span>: <span class="pl-s">127.0.0.1</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">Task should run once on the local host</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">Task is skipped.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate">
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">core</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.4.3.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/selivan/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]"><pre class="notranslate"><code class="notranslate">ansible 2.4.3.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/selivan/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ANSIBLE_NOCOWS(/etc/ansible/ansible.cfg) = True"><pre class="notranslate"><code class="notranslate">ANSIBLE_NOCOWS(/etc/ansible/ansible.cfg) = True
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Ansible host: Ubuntu GNU/Linux 16.04 Xenial<br>
Managed host: Ubuntu GNU/Linux 16.04 Xenial</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Named block statements (<a href="http://docs.ansible.com/ansible/latest/playbooks_blocks.html" rel="nofollow">http://docs.ansible.com/ansible/latest/playbooks_blocks.html</a>) do not work in handlers. Ansible does not see that handler at all.</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="- hosts: all
  become: yes
  tasks:
    - name: install nginx config
      template: src=nginx.conf dest=/etc/nginx/nginx.conf mode=0644
      notify: reload nginx
  handlers:
    - name: reload nginx
      block:
        - shell: nginx -t
        - service: name=nginx state=reloaded"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">become</span>: <span class="pl-s">yes</span>
  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">name</span>: <span class="pl-s">install nginx config</span>
      <span class="pl-ent">template</span>: <span class="pl-s">src=nginx.conf dest=/etc/nginx/nginx.conf mode=0644</span>
      <span class="pl-ent">notify</span>: <span class="pl-s">reload nginx</span>
  <span class="pl-ent">handlers</span>:
    - <span class="pl-ent">name</span>: <span class="pl-s">reload nginx</span>
      <span class="pl-ent">block</span>:
        - <span class="pl-ent">shell</span>: <span class="pl-s">nginx -t</span>
        - <span class="pl-ent">service</span>: <span class="pl-s">name=nginx state=reloaded</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Handler <code class="notranslate">reload nginx</code> should run and execute both modules: first <code class="notranslate">shell</code>, then, if <code class="notranslate">shell</code> returned success, execute <code class="notranslate">service</code>.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ERROR! The requested handler 'reload nginx' was not found in either the main handlers list nor in the listening handlers list"><pre class="notranslate"><code class="notranslate">ERROR! The requested handler 'reload nginx' was not found in either the main handlers list nor in the listening handlers list
</code></pre></div>