Variable registration step, ignore_errors, and idempotency

I’m writing a playbook that runs an initial git commit on a folder if there has not yet been a commit. I check this using:

`

  • name: Get commit count
    command: git rev-list HEAD --count chdir={{ project_path }}
    ignore_errors: yes
    register: git_commit_count

`

If there have been no commits, this command returns an error, in which case I then conditionally run a few other git-related steps. I have two issues with this:

  1. Even if the error is ignored, it is still reported in the log display even if I have not enabled verbose mode
  2. This step always reports “changed” which breaks my idempotency check that ensures changed=0 on a second run
    Is there a good way to work around this? Can I take this step “off the record”?

Instead of ignore_errors: True, consider:

failed_when: False

The reporting of changed always can be fixed with

changed_when: False

Perfect, exactly what I needed. Thanks!