Technotes

Technotes for future me

Puppet Duplicate Resources with PuppetDB

Puppet Duplicate Resources with PuppetDB

If you’re using puppet and exported resources and get an error while running the puppet agent showing
root@server:$ 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
root@puppet-master:$ 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.

SELECT * FROM catalog_resources WHERE title LIKE '%sshkey[blaataap.adelerhof.eu]%';

DELETE FROM catalog_resources WHERE title LIKE '%blaataap%';
Last updated on 31 Jan 2021
Published on 11 Dec 2019
Edit on GitHub