Is there a module that can encrypt a file with vault in tasks?

I use playbook to locally generate a private key, and after that I’d like to encrypt it with vault so another playbook can use it to copy to a remote hosts.

Is there a module that can encrypt a file with vault? Or should I simply use the command module to run “ansible-vault encrypt”?

no, but there is a filter
https://docs.ansible.com/ansible/devel/collections/ansible/builtin/vault_filter.html

That works for me. Thanks a lot.