Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running task or play in check_mode from playbook #12498

Closed
wrouesnel opened this issue Sep 23, 2015 · 2 comments · Fixed by #16056
Closed

Allow running task or play in check_mode from playbook #12498

wrouesnel opened this issue Sep 23, 2015 · 2 comments · Fixed by #16056
Labels
feature This issue/PR relates to a feature request.
Milestone

Comments

@wrouesnel
Copy link
Contributor

Ansible check_mode allows determining if a task would have changed something, but only on the level of an entire play.

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.

This can be replicated by comparing mtimes locally and remotely, but leads to complicated syntax for something the existing feature can already provide.

Ideally something like this would be possible:

- 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

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).

@amenonsen
Copy link
Contributor

I wanted to do exactly the same thing and, after some discussion on the list, I submitted #7439 at mpdehaan's request, but then he decided he didn't want it after all. The code won't apply any more, I imagine, but it should be easy enough to adapt for v2 if you're interested.

@jimi-c jimi-c added this to the next milestone Sep 25, 2015
@jimi-c jimi-c removed the P3 label Dec 7, 2015
@robinro
Copy link
Contributor

robinro commented May 30, 2016

This would also make testcases a lot nicer to write. The check_mode support in many modules is flaky, since they are not thoroughly tested. Currently in the integration tests only the template module is included. For some modules (i.e. git) the code in check_mode differs quite a bit from normal mode.

@jimi-c jimi-c modified the milestones: 2.2.0, stable-2.1 Jun 18, 2016
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_idea labels Mar 2, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue/PR relates to a feature request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants