Last night I ran a playbook from a wrong branch that referenced an old inventory file with old IPs for each server, and deployed a dev build to a production machine. What would be a a good practice to avoid such mistake from happening in the future? How can I isolate environments better?
The best practice is to separate production and staging(testing) inventory. See Staging vs Production.
This way you pick with -i what you are targeting.
To make it more robust you might want to clone a separate structure for production and restrict access to it. Pull from staging before deploying to production.