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

<ul dir="auto">
<li>Feature Idea</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"><pre class="notranslate"><code class="notranslate">ansible 2.0.1.0
</code></pre></div>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">--check currently is only available as command line option and sometimes people forget so it would be nice if there is something like <code class="notranslate">check_mode: True</code> in playbook so we don't have to worry about command line options.</p>
<p dir="auto">The output of check mode run should be more obvious to indicate that this is a check only.</p>
<p dir="auto">Thanks</p>
<p dir="auto">Ansible check_mode allows determining if a task <em>would</em> have changed something, but only on the level of an entire play.</p>
<p dir="auto">But there are obvious cases where idempotency requires being able to change the order of events - i.e. check if a file would be changed, if so, stop a daemon and change the file - otherwise do nothing.</p>
<p dir="auto">This can be replicated by comparing mtimes locally and remotely, but leads to complicated syntax for something the existing feature can already provide.</p>
<p dir="auto">Ideally something like this would be possible:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: webservers
  tasks:
  - copy: src=monitoredfile dest=monitoredfile
    check_mode: true
    register: copy_check

  - service: name=webserver state=stopped
    when: copy_check.changed

  - copy: src=monitoredfile dest=monitoredfile
    when: copy_check.changed

  - service: name=webserver state=started
    when: copy_check.changed"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">webservers</span>
  <span class="pl-ent">tasks</span>:
  - <span class="pl-ent">copy</span>: <span class="pl-s">src=monitoredfile dest=monitoredfile</span>
    <span class="pl-ent">check_mode</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">register</span>: <span class="pl-s">copy_check</span>

  - <span class="pl-ent">service</span>: <span class="pl-s">name=webserver state=stopped</span>
    <span class="pl-ent">when</span>: <span class="pl-s">copy_check.changed</span>

  - <span class="pl-ent">copy</span>: <span class="pl-s">src=monitoredfile dest=monitoredfile</span>
    <span class="pl-ent">when</span>: <span class="pl-s">copy_check.changed</span>

  - <span class="pl-ent">service</span>: <span class="pl-s">name=webserver state=started</span>
    <span class="pl-ent">when</span>: <span class="pl-s">copy_check.changed</span></pre></div>
<p dir="auto">This is simple and readable, and helps in dealing with services which may be monitoring config directories for new files but which would might like to try and avert for changes like that (exim with a perl interpreter can be a problem in this regard).</p>