<p dir="auto">Sorry if this is a repeat/duplicate/similar, there are tons of issues when using <code class="notranslate">limit</code> as the search term.</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Feature Idea</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">limit</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook 2.4.0.0
  config file = 
  configured module search path = [u'/Users/lynchg/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/lynchg/.virtualenvs/a2x/lib/python2.7/site-packages/ansible
  executable location = /Users/lynchg/.virtualenvs/a2x/bin/ansible-playbook
  python version = 2.7.13 (default, Dec 18 2016, 07:03:34) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]"><pre class="notranslate"><code class="notranslate">ansible-playbook 2.4.0.0
  config file = 
  configured module search path = [u'/Users/lynchg/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/lynchg/.virtualenvs/a2x/lib/python2.7/site-packages/ansible
  executable location = /Users/lynchg/.virtualenvs/a2x/bin/ansible-playbook
  python version = 2.7.13 (default, Dec 18 2016, 07:03:34) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">NA</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">NA</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">While it is possible to do <code class="notranslate">delegate_facts</code> with <code class="notranslate">with_items</code> to handle <code class="notranslate">--limit</code> being used, this has a very high performance impact, because it is single forked.  So ideal option would be to add a play key, and exposed variable that can be used - so then limit would work similar to batch/serial.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">NA</p>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">It should be possible to do e.g.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook webservers.yml -l 'foo.example.com'"><pre class="notranslate"><code class="notranslate">ansible-playbook webservers.yml -l 'foo.example.com'
</code></pre></div>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: dbservers
  limit: []
  gather_facts: True

- hosts: webservers
  limit: &quot;{{  ansible_play_limit|default([]) }}&quot;
  tasks:
    ..."><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">dbservers</span>
  <span class="pl-ent">limit</span>: <span class="pl-s">[]</span>
  <span class="pl-ent">gather_facts</span>: <span class="pl-c1">True</span>

- <span class="pl-ent">hosts</span>: <span class="pl-s">webservers</span>
  <span class="pl-ent">limit</span>: <span class="pl-s"><span class="pl-pds">"</span>{{  ansible_play_limit|default([]) }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">tasks</span>:
    <span class="pl-s">...</span></pre></div>
<p dir="auto">This would also align with the recent changes to expose <code class="notranslate">ansible_play_hosts</code> and <code class="notranslate">ansible_play_batch</code></p>
<p dir="auto">The logic I see working would be something similar to the pattern <code class="notranslate">webservers:&amp;limit</code>, i.e. only hosts that are in the play group <em>and</em> are in the limit.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">It's currently necessary to completely ignore the <code class="notranslate">--limit</code> functionality and use a workaround of targets, e.g.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook webservers.yml -e 'target=foo.example.com'"><pre class="notranslate"><code class="notranslate">ansible-playbook webservers.yml -e 'target=foo.example.com'
</code></pre></div>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: dbservers
  gather_facts: True

- hosts: &quot;{{ target|default('webservers') }}&quot;
  tasks:
    ..."><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">dbservers</span>
  <span class="pl-ent">gather_facts</span>: <span class="pl-c1">True</span>

- <span class="pl-ent">hosts</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ target|default('webservers') }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">tasks</span>:
    <span class="pl-s">...</span></pre></div>
<p dir="auto">While this is nearly as easy, it can be confusing to people new to ansible, but ultimately it also makes <code class="notranslate">--limit</code> basically useless.</p>
<h5 dir="auto">Issue Type:</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">Ansible Version:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.0.1.0
  config file = /home/etienne/repo/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.0.1.0
  config file = /home/etienne/repo/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">Ansible Configuration:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ cat /home/etienne/repo/ansible.cfg
[defaults]
hostfile = /home/etienne/repo/config/inventory
display_skipped_hosts = False
nocows=1
vault_password_file = ./config/toto

[ssh_connection]
ssh_args = -F ./config/ssh_config -o ControlMaster=auto -o ControlPersist=60s"><pre class="notranslate"><code class="notranslate">$ cat /home/etienne/repo/ansible.cfg
[defaults]
hostfile = /home/etienne/repo/config/inventory
display_skipped_hosts = False
nocows=1
vault_password_file = ./config/toto

[ssh_connection]
ssh_args = -F ./config/ssh_config -o ControlMaster=auto -o ControlPersist=60s
</code></pre></div>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Running from an up-to-date Archlinux</p>
<p dir="auto">Managing a grape of LXC containers running Debian Wheezy inside Debian Wheezy hosts.</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Until ansible 2.0, I used to maintain a "global" handlers file, which contains very generic handlers like apache restart, monit restart etc. used in several of my roles. This file is not stored in any role, but "included" in my various playbooks. It used to work.</p>
<p dir="auto">Since ansible 2.0, handlers are silently ignored. I think it is somehow related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="121571960" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/13507" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/13507/hovercard" href="https://github.com/ansible/ansible/issues/13507">#13507</a></p>
<h5 dir="auto">Steps To Reproduce:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ cd repo
$ cat roles/backjob/tasks/main.yml

---
- template: src=delayed_jobs_monit.j2
      dest=/etc/monit/monitrc.d/delayed_jobs_toto
  notify:
    - Restart monit
  tags:
    - backjob
    - monit
$ cat vendor_specific.yml

---
- hosts: sd-83787-dintec
  roles:
    - backjob
  handlers:
    - include: config/handlers.yml
$ cat config/handlers.yml

---
- name: Restart monit
  service: name=monit state=restarted
$ ansible-playbook vendor_specific.yml"><pre class="notranslate"><code class="notranslate">$ cd repo
$ cat roles/backjob/tasks/main.yml

---
- template: src=delayed_jobs_monit.j2
      dest=/etc/monit/monitrc.d/delayed_jobs_toto
  notify:
    - Restart monit
  tags:
    - backjob
    - monit
$ cat vendor_specific.yml

---
- hosts: sd-83787-dintec
  roles:
    - backjob
  handlers:
    - include: config/handlers.yml
$ cat config/handlers.yml

---
- name: Restart monit
  service: name=monit state=restarted
$ ansible-playbook vendor_specific.yml
</code></pre></div>
<p dir="auto">There is nothing special in the <code class="notranslate">host_vars/sd-83787-dintec.yml</code> file.</p>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">When the template module execution push a new version of the file, the handler <code class="notranslate">Restart monit</code> must be executed.</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">The playbook is successfully ran, but handler is silently ignored: nothing related to handler is output, even with -vvvv</p>
<p dir="auto">However, if I directly add the handler in the playbook:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ cat vendor_specific.yml

---
- hosts: sd-83787-dintec
  roles:
    - backjob
  handlers:
    - name: Restart monit
      service: name=monit state=restarted
    #- include: config/handlers.yml"><pre class="notranslate"><code class="notranslate">$ cat vendor_specific.yml

---
- hosts: sd-83787-dintec
  roles:
    - backjob
  handlers:
    - name: Restart monit
      service: name=monit state=restarted
    #- include: config/handlers.yml
</code></pre></div>
<p dir="auto">handler is ran as expected.</p>