If your are using a clear password in your YAML file, you can encrypt the file via Ansible-vault.
- How to encrypt the credentials ?
#ansible-vault encrypt MyCredentials.yml
New Vault password: <Enter the password and stored in a safe place>
Confirm New Vault password: <Enter the same password>
Encryption successful
- How to view the encrypted credentials ?
#ansible-vault view MyCredentials.yml
Vault password: <Enter the password previously chosen>
- How to change data in your file (for example your credentials) ?
decrypt the file MyCredentials.yml
User@Ansible-Host:~/> ansible-vault decrypt MyCredentials.yml
Vault password: <known_key>
Decryption successful
Edit the file with your preferred editor (vim/nano) by changing the data.
Then encrypt the file again
User@Ansible-Host:~/> ansible-vault encrypt MyCredentials.yml
New Vault password: <known_key>
Confirm New Vault password: <known_key>
Encryption successful