Ansible-vault encrypt; return value if already encrypted

Hello,

I would like to run the encryption of some files automatically during git commit.
Unfortunately ansible-vault returns an error if the files are already encrypted, but this is obviously not an error, it’s the expected state.
But I need a return value of 0 (even if the files are already encrypted) in order to run it during the pre-commit checks.
Any Idea how to do that?

Thanks a lot :slight_smile:
Thomas

No, not currently, but you can ‘skip’ those files if you use the ‘vault_encrypted’ test:

- shell: ansible-vault .... {{ item}}
  when: '{{ lookup("file", item) is not vault_encrypted}}'
  loop: ' {{ myfiles}}'

Thanks a lot!
I need this in a shell script (git hook) - Is there such a test for the shell as well?

adding a ‘vaulted file test’ Add vaulted_file test by bcoca · Pull Request #83717 · ansible/ansible · GitHub

But to test from shell, use ansible? just have a playbook with an assert and have it pass/fail as needed