WARNING: Solving problems like these will always be both dangerous and tedious. Please understand that some of the packages in your system are critical to the function of the system. Making changes involving such packages can be more difficult. Make sure you understand whatever you are thinking of doing, watch out for details, ask around for help, make backups/snapshots before trying anything as it's easy to make things worse instead of better. For some changes it may be necessary to boot a rescue disk so that you don't have to rely on the system you are trying to fix.
In my case I found that something had gone wrong and many packages had been updated without the older versions being removed. Attempts to rebuild the RPM DB did not solve the problem.
One solution that is working is simply to remove the older version and reinstall the newer version.
Looking at the error output each line basically says Update Package is a duplicate with Previous Package, ie:
kernel-headers-2.6.32-431.17.1.el6.x86_64 is a duplicate with kernel-headers-2.6.32-358.23.2.el6.x86_64
The following seems to work for me:
rpm --erase --nodeps --noscript kernel-headers-2.6.32-358.23.2.el6.x86_64
The command tells RPM to remove the specific Previous Package without removing any dependencies or running any scripts associated with the task.
Next the package needs to be reinstalled:
yum reinstall kernel-headers
This time there's no need to specify the exact package version as yum will look for the most recent version and reinstall it.
Yum will output the result of its Yum Check operation during each run. Keep doing this until there are no more duplicate packages listed.
Note that you can query the RPM database directly. If you see lots of messages that include the string glibc, for example, you can get a simple list of packages which have that string in their names like this:
rpm -qa | grep glibc | sort
Which might produce something like:
Now it's more obvious that the previous version of glibc-common must be removed:
rpm --erase --nodeps --noscript glibc-common-2.17-157.el7_3.4.x86_64
yum reinstall glibc-common