I previously wrote about how to setup Git integration with Puppet but with the way it’s set up, the code change you made is not deployed to Puppet master right away. We need to do something about this.
First of all, it’s quite easy to set up a webhook in GitLab to tell Puppet that “code is pushed, so deploy now”. Please see this documentation on how to set it up. This is the best way to go about deploying the code change to Puppet master.
What if your source control such as GitHub or GitLab cannot reach your instance of Puppet master because the Puppet master is behind a firewall or router or whatever? Here is a poor man’s solution to it.
Generate API Token
We will utilize Puppet’s API to get the code deployed. Let’s generate an API token.
- ssh into Puppet master.
- Execute the following command to generate the token. –lifetime 365d in the command below means the token will expire in 365 days.
$ puppet-access login --lifetime 365d
- The API token is generated at the following location.
Deploy the Code
- Now execute the command to deploy the code from Git.
$ puppet-code deploy --all --wait
- On any agent or on Puppet master, execute the following command to apply the change.
$ sudo /opt/puppetlabs/bin/puppet agent -t
# puppet agent -t
Like I mentioned, the best way to get the code change to be deployed to Puppet is webhook. It basically means that Git server sends HTTPS request to Puppet master to let it know that there was a code change and Puppet does its job to sync the code. Otherwise, you could use the technique above. To take it a little further, bash script could be created to execute
puppet-code deploy and
puppet agent -t and get it to be run as a cron job. It’s really up to you.