Refactor Puppet code for the Jenkins master

Originally created by @intrigeri on #7105 (Redmine)

Parent Task: #6056 (closed)

Edited by intrigeri