At 2013-08-13 20:33:12 -0400, [email protected] wrote:
>
> However, there's no way to run just *one* task in check mode, so it
> seems this is a feature request for check at task level.
>
> apt: ...
> check_mode: True

Hi.

I'm sorry it's taken so long, but here's a pull request that allows
individual tasks to be run in check mode:

    https://github.com/ansible/ansible/pull/7439

The patch was written by my colleague Carlos Chapi (Cc:ed) and tested by
me (the original motivation for this feature was to find out if the apt
module would install certain packages, so as to take some extra actions
before and afterwards only if something's going to be installed).

For example (since the original context was so long ago):

    - name: Check if Postgres needs to be installed
      apt: name=postgresql-9.3 state=installed
      check_mode: True
      register: wouldinstall

    - name: Suppress autostart with policy-rc.d
      copy:
        content="#!/bin/bash\nexit 101\n"
        dest=/usr/sbin/policy-rc.d mode=0755
      when: wouldinstall.changed

    - name: Install Postgres
      apt: name=postgresql-9.3 state=installed
      when: wouldinstall.changed
      register: install

    - name: Remove policy-rc.d
      file: path=/usr/sbin/policy-rc.d state=absent
      when: install.changed

(My original proposal involved an "apt-wouldinstall" module, but Michael
suggested the much more sensible per-task check_mode setting.)

I can imagine many other "do x if y would happen" use-cases for this.

Thanks.

-- ams

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20140517172554.GA13533%40toroid.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to