If you’re using puppet and exported resources and get an error while running the puppet agent showing
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: A duplicate resource was found while collecting exported resources, with the type and title CMD[Title] on node HOSTNAME Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run
Then you’ve got a duplicate resource in the puppetdb which typically happens when you export resources to be imported else which has already happened, usually because you’ve rebuilt the host and not deactivated it prior
puppet node deactivate HOSTNAME
To resolve this you can remove the previous exports from the database. I’ve used a select statement first to check what is returned
Postgres:
su - postgres psql puppetdb > SELECT * FROM catalog_resources WHERE title LIKE '%Title%'; # DELETE FROM catalog_resources WHERE title LIKE '%Title%'; |
Built in PuppetDB (HSQLDB):
systemctl stop puppetdb cd /var/lib/puppetdb/db/ cat -n db.script | grep <Title> sed -i.bak -e '<n>d' db.script systemctl start puppetdb |
Please replace <Title> with the title of your export and replace <n> with the line number that is returned from the cat command.
Some of this information is from Chris Cowley and he’s done a better job and writing about it.