The yamllint command line tool does what you want:
sudo pip install yamllint
In particular, it has a key-duplicates rule that detects key-duplicates and keys by rewriting each other:
$ yamllint test.yml test.yml 1:1 warning missing document start "---" (document-start) 4:5 error duplication of key ":name" in mapping (key-duplicates)
(It has many other rules that you can enable / disable or configure.)
Adrien vergΓ©
source share