<p dir="auto">I upgraded from ansible 1.3 to ansible 1.6 and my asynchronous tasks are not working properly when those have to be SKIPPED. (when are not skipped everything works ok). This is my task to reproduce the error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Create screen session to run dd on new disk (async mode)
    shell: /bin/dd if={{ ebs_device }} of=/dev/null bs=1024k
    async: 36000
    poll: 0
    tags: rundd 
    when: ebs_iops != 0"><pre lang="ansible" class="notranslate"><code class="notranslate">- name: Create screen session to run dd on new disk (async mode)
    shell: /bin/dd if={{ ebs_device }} of=/dev/null bs=1024k
    async: 36000
    poll: 0
    tags: rundd 
    when: ebs_iops != 0
</code></pre></div>
<p dir="auto">This is executed as follows (Note: ebs_iops=0)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook -i cluster-oe setup.yml -s --ask-vault-pass --tags rundd"><pre lang="ansible" class="notranslate"><code class="notranslate">ansible-playbook -i cluster-oe setup.yml -s --ask-vault-pass --tags rundd
</code></pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [common | Create screen session to run dd on new disk (async mode)] *****
skipping: [X.X.X.X]
Traceback (most recent call last):
  File &quot;/usr/bin/ansible-playbook&quot;, line 317, in &lt;module&gt;
    sys.exit(main(sys.argv[1:]))
  File &quot;/usr/bin/ansible-playbook&quot;, line 257, in main
    pb.run()
  File &quot;/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py&quot;, line 291, in run
    if not self._run_play(play):
  File &quot;/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py&quot;, line 644, in _run_play
    if not self._run_task(play, task, False):
  File &quot;/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py&quot;, line 421, in _run_task
    results = self._run_task_internal(task)
  File &quot;/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py&quot;, line 385, in _run_task_internal
    self.runner_callbacks.on_async_ok(host, res, poller.runner.vars_cache[host]['ansible_job_id'])
KeyError: 'ansible_job_id'
TASK: [common | Create screen session to run dd on new disk (async mode)] *****
skipping: [X.X.X.X]
Traceback (most recent call last):
  File &quot;/usr/bin/ansible-playbook&quot;, line 317, in &lt;module&gt;
    sys.exit(main(sys.argv[1:]))
  File &quot;/usr/bin/ansible-playbook&quot;, line 257, in main
    pb.run()
  File &quot;/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py&quot;, line 291, in run
    if not self._run_play(play):
  File &quot;/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py&quot;, line 644, in _run_play
    if not self._run_task(play, task, False):
  File &quot;/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py&quot;, line 421, in _run_task
    results = self._run_task_internal(task)
  File &quot;/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py&quot;, line 385, in _run_task_internal
    self.runner_callbacks.on_async_ok(host, res, poller.runner.vars_cache[host]['ansible_job_id'])
KeyError: 'ansible_job_id'"><pre lang="ansible" class="notranslate"><code class="notranslate">TASK: [common | Create screen session to run dd on new disk (async mode)] *****
skipping: [X.X.X.X]
Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 317, in &lt;module&gt;
    sys.exit(main(sys.argv[1:]))
  File "/usr/bin/ansible-playbook", line 257, in main
    pb.run()
  File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", line 291, in run
    if not self._run_play(play):
  File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", line 644, in _run_play
    if not self._run_task(play, task, False):
  File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", line 421, in _run_task
    results = self._run_task_internal(task)
  File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", line 385, in _run_task_internal
    self.runner_callbacks.on_async_ok(host, res, poller.runner.vars_cache[host]['ansible_job_id'])
KeyError: 'ansible_job_id'
TASK: [common | Create screen session to run dd on new disk (async mode)] *****
skipping: [X.X.X.X]
Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 317, in &lt;module&gt;
    sys.exit(main(sys.argv[1:]))
  File "/usr/bin/ansible-playbook", line 257, in main
    pb.run()
  File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", line 291, in run
    if not self._run_play(play):
  File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", line 644, in _run_play
    if not self._run_task(play, task, False):
  File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", line 421, in _run_task
    results = self._run_task_internal(task)
  File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", line 385, in _run_task_internal
    self.runner_callbacks.on_async_ok(host, res, poller.runner.vars_cache[host]['ansible_job_id'])
KeyError: 'ansible_job_id'
</code></pre></div>
<p dir="auto">Ansible version:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible --version
ansible 1.6.1"><pre lang="ansible" class="notranslate"><code class="notranslate">ansible --version
ansible 1.6.1
</code></pre></div>
<h5 dir="auto">Issue Type: Bug Report</h5>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.6.1, devel</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Centos 6.5, OS X 10.9.2</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">An async task with 'poll: 0' fails only when the 'when' condition causes it to be skipped. If I remove the poll option or set it to a number higher than 0, the task is successfully skipped. If I remove the 'when' condition, the async task is successful with 'poll' set to 0.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">Create an async task with 'poll: 0' and a when condition that causes it to be skipped.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: test
  hosts: localhost

  tasks:
    - name: a local task
      shell: echo hello
      async: 30
      poll: 0
      when: a_variable is defined"><pre class="notranslate"><code class="notranslate">- name: test
  hosts: localhost

  tasks:
    - name: a local task
      shell: echo hello
      async: 30
      poll: 0
      when: a_variable is defined
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">The async task should be skipped.</p>
<h5 dir="auto">Actual Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [a local task] **********************************************************
skipping: [localhost]
Traceback (most recent call last):
  File &quot;/Users/jyoung/lib/ansible-main/bin/ansible-playbook&quot;, line 317, in &lt;module&gt;
    sys.exit(main(sys.argv[1:]))
  File &quot;/Users/jyoung/lib/ansible-main/bin/ansible-playbook&quot;, line 257, in main
    pb.run()
  File &quot;/Users/jyoung/lib/ansible-main/lib/ansible/playbook/__init__.py&quot;, line 319, in run
    if not self._run_play(play):
  File &quot;/Users/jyoung/lib/ansible-main/lib/ansible/playbook/__init__.py&quot;, line 673, in _run_play
    if not self._run_task(play, task, False):
  File &quot;/Users/jyoung/lib/ansible-main/lib/ansible/playbook/__init__.py&quot;, line 449, in _run_task
    results = self._run_task_internal(task)
  File &quot;/Users/jyoung/lib/ansible-main/lib/ansible/playbook/__init__.py&quot;, line 413, in _run_task_internal
    self.runner_callbacks.on_async_ok(host, res, poller.runner.vars_cache[host]['ansible_job_id'])
KeyError: 'ansible_job_id'"><pre class="notranslate"><code class="notranslate">TASK: [a local task] **********************************************************
skipping: [localhost]
Traceback (most recent call last):
  File "/Users/jyoung/lib/ansible-main/bin/ansible-playbook", line 317, in &lt;module&gt;
    sys.exit(main(sys.argv[1:]))
  File "/Users/jyoung/lib/ansible-main/bin/ansible-playbook", line 257, in main
    pb.run()
  File "/Users/jyoung/lib/ansible-main/lib/ansible/playbook/__init__.py", line 319, in run
    if not self._run_play(play):
  File "/Users/jyoung/lib/ansible-main/lib/ansible/playbook/__init__.py", line 673, in _run_play
    if not self._run_task(play, task, False):
  File "/Users/jyoung/lib/ansible-main/lib/ansible/playbook/__init__.py", line 449, in _run_task
    results = self._run_task_internal(task)
  File "/Users/jyoung/lib/ansible-main/lib/ansible/playbook/__init__.py", line 413, in _run_task_internal
    self.runner_callbacks.on_async_ok(host, res, poller.runner.vars_cache[host]['ansible_job_id'])
KeyError: 'ansible_job_id'
</code></pre></div>