A best practice approach for this is to start with a group_vars/ subdirectory named after the group. Inside of this subdirectory, create two files named vars and vault. Inside of the vars file, define all of the variables needed, including any sensitive ones. Next, copy all of the sensitive variables over to the vault file and prefix these variables with vault_. You should adjust the variables in the vars file to point to the matching vault_ variables using jinja2 syntax, and ensure that the vault file is vault encrypted. - Source: https://docs.ansible.com/ansible/2.8/user_guide/playbooks_best_practices.html
I am using dynamic inventory and could not understand these best practices 100%.
group_vars/all/vars
group_vars/all/vault
content of vars:
db_username: ""
db_password: ""
content of vault:
vault_db_username: admin
vault_db_password: ****
Will this work?