Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webhook pulling wrong version of git repo #551

Open
jmcdonal opened this issue Mar 10, 2021 · 1 comment
Open

webhook pulling wrong version of git repo #551

jmcdonal opened this issue Mar 10, 2021 · 1 comment

Comments

@jmcdonal
Copy link

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: Open Source Version 7.4
  • Ruby: 2.65
  • Distribution: RedHat 7.9
  • Module version: n/a

How to reproduce (e.g Puppet code you use)

Stock rpm install, out of the box configuration.

What are you seeing

The github webhook is sent and received by the puppet webhook and r10k is deploying the environment but it is using an older copy of the repo. e.g. :
Mar 10 13:14:37 hi-automation bundle: 2021-03-10T19:14:37.498Z 1319 TID-hnuin Deploy::EnvironmentWorker JID-e1230c37c97b53a50a57978c INFO: Environment production is now at 24a5fdedf2e6d655624dbded615394cebb645340

but the head is at: 72c9b6322aee2531e13c2796f8127baa34b492d6
$ git log
commit 72c9b6322aee2531e13c2796f8127baa34b492d6 (HEAD -> production, origin/production, origin/HEAD)
Author:
Date: Wed Mar 10 13:14:30 2021 -0600

test

commit 24a5fdedf2e6d655624dbded615394cebb645340
Author:
Date: Wed Mar 10 11:05:06 2021 -0600

test

What behaviour did you expect instead

I was expecting that the system would pull the latest version of the repo, not the previous version. It also seems to be stuck on the older version, so if I make a series of commits in quick secession, the repo is 'stuck' at this version.

Is there something I need to purge on the system after each run?

Output log

Any additional information you'd like to impart

@alexjfisher
Copy link
Member

Sounds like you might have environment caching enabled?

If so, you can configure r10k with a postrun script that calls the puppetserver admin api to clear the cache after each deployment.

Here's an example from a profile::r10k class.

$postrun_script = '/usr/local/bin/r10k_postrun'
file { $postrun_script:
  ensure  => file,
  owner   => 'puppet',
  group   => 'puppet',
  mode    => '0700',
  content => template('profile/r10k/r10k_postrun.erb'),
}
      
class { 'r10k':
  version => '3.1.0',
  sources => {
    'puppet' => {
      'remote'  => '[email protected]:puppet/control-repo.git',    
      'basedir' => '/etc/puppetlabs/code/environments',
    },
 },
 postrun => [
   $postrun_script,
   '$modifiedenvs', # Occurrences of the string $modifiedenvs in the postrun command will be replaced with the current environment(s) being deployed.
  ],
}

The postrun script is a template. (My version also pokes Foreman, but I've removed those lines for clarity).
(If you're not already, you definitely want to be calling generate types as well as clearing the environment cache.)

#!/bin/bash

# R10k calls this script with a list of environments it has updated.
# For each environment, `puppet generate types is called` and the environment cache invalidated.

for environment in "$@"
do
  /opt/puppetlabs/bin/puppet generate types --codedir /etc/puppetlabs/code --environment $environment
  /bin/curl --noproxy localhost -i -k --cert /etc/puppetlabs/puppet/ssl/certs/<%= @facts['fqdn'] %>.pem --key /etc/puppetlabs/puppet/ssl/private_keys/<%= @facts['fqdn'] %>.pem --cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem -X DELETE "https://localhost:8140/puppet-admin-api/v1/environment-cache?environment=${environment}"
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants