Function: ansible-auto-decrypt-encrypt

ansible-auto-decrypt-encrypt is a natively compiled function defined in ansible.el.

Signature

(ansible-auto-decrypt-encrypt)

Documentation

Decrypt current buffer if it is a vault encrypted file.

Also, automatically encrypts the file before saving the buffer.

Source Code

;; Defined in /nix/store/ihs1wd4idvapzygy87ss7ddr2pwcpsxg-emacs-packages-deps/share/emacs/site-lisp/elpa/ansible-20260607.1852/ansible.el
(defun ansible-auto-decrypt-encrypt ()
  "Decrypt current buffer if it is a vault encrypted file.
Also, automatically encrypts the file before saving the buffer."
  (let ((vault-file? (string-match-p
                      "\$ANSIBLE_VAULT;[0-9]+\.[0-9]+"
                      (buffer-substring-no-properties
                       (point-min) (point-max)))))
    (when vault-file?
      (condition-case _
          (progn
            (ansible-decrypt-buffer)
            (add-hook 'before-save-hook 'ansible-encrypt-buffer nil t)
            (add-hook 'after-save-hook  'ansible-decrypt-buffer nil t))
        (error
         (message
          (concat "Could not decrypt file. Make sure "
                  "`ansible-vault-password-file' or the environment variable "
                  "ANSIBLE_VAULT_PASSWORD_FILE is correctly set")))))))