Forcing a task to not show as "changed"

Hi there,

I have a playbook with the following set of tasks:

  • name: Check if the GPG key is present
    sudo: yes
    sudo_user: foobar
    command: gpg --list-keys XXXXX
    ignore_errors: true
    register: gpg_result

  • name: Import the signing GPG key
    sudo: yes
    sudo_user: foobar
    command: gpg --import /home/foobar/pubkey.gpg
    when: gpg_result|failed

The idea being, check if a GPG key is present, and, if not, import it. I’d like to add some sort of flag that states that the first task (which always runs) doesn’t actually modify anything, and thus shouldn’t be counted as having “changed”. Is there a way to do this? Note that this isn’t the only example - the general pattern of “run command, depending on result, run other(s)” has come up before.

Thanks,
–Andrew D

There is a pull request in queue for this:

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

This has now been implemented:

http://www.ansibleworks.com/docs/playbooks2.html#overriding-changed-result
https://github.com/stoned/ansible/blob/eb45f07ae3a64a8ff675bd0846d156522c1e14fc/test/playbook-changed_when.yml