puppetlabs / control-repo

A control repository template
Apache License 2.0
204 stars 510 forks source link

config_version.sh fails if there is no initalized git repo #86

Closed milesstoetzner closed 2 years ago

milesstoetzner commented 4 years ago

Describe the Bug

If git is installed on the system but the control repo is actually not a git repo the scripts/config_version.sh script fails.

Error:

puppet agent -t

Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Execution of config_version command `/etc/puppetlabs/code/environments/production/scripts/config_version.sh /etc/puppetlabs/code/environments production` failed: Execution of '/etc/puppetlabs/code/environments/production/scripts/config_version.sh /etc/puppetlabs/code/environments production' returned 128: fatal: not a git repository: '/etc/puppetlabs/code/environments/production/.git' on node XXXXXXXX
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

Expected Behavior

The script should not pass the "git availability" check if there is no git repo initalized and therefore return a date as config version.

Solution

I currently fixed it by using the following condition:

elif type git >/dev/null && [ -d "$1/$2/.git" ]; then

Steps to Reproduce

Assumptions:

Steps to reproduce the behavior:

  1. rm -rf /etc/puppetlabs/code/environments/production/.git
  2. /etc/puppetlabs/code/environments/production/scripts/config_version.sh /etc/puppetlabs/code/environments production or puppet agent -t

Environment

Additional Context

I deployed the puppetserver using foreman and I currently copy the environment files using scp to the server.

gudsingh commented 2 years ago

Describe the Bug

If git is installed on the system but the control repo is actually not a git repo the scripts/config_version.sh script fails.

Error:

puppet agent -t

Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Execution of config_version command `/etc/puppetlabs/code/environments/production/scripts/config_version.sh /etc/puppetlabs/code/environments production` failed: Execution of '/etc/puppetlabs/code/environments/production/scripts/config_version.sh /etc/puppetlabs/code/environments production' returned 128: fatal: not a git repository: '/etc/puppetlabs/code/environments/production/.git' on node XXXXXXXX
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

Expected Behavior

The script should not pass the "git availability" check if there is no git repo initalized and therefore return a date as config version.

Solution

I currently fixed it by using the following condition:

elif type git >/dev/null && [ -d "$1/$2/.git" ]; then

Steps to Reproduce

Assumptions:

  • there is a production environment that had been once a git repository (see "Additional Context")
  • the previous checks in the script are failing too (no exisiting r10k etc).
  • git is installed

Steps to reproduce the behavior:

  1. rm -rf /etc/puppetlabs/code/environments/production/.git
  2. /etc/puppetlabs/code/environments/production/scripts/config_version.sh /etc/puppetlabs/code/environments production or puppet agent -t

Environment

  • control repo version: latest resp. commitID: 882089207ccc0f326007c0dbdb415426f6e100f2
  • Ubuntu 18.04
  • git version 2.17.1

Additional Context

I deployed the puppetserver using foreman and I currently copy the environment files using scp to the server.

Hi there,

I am getting same error and I did not understand the solution.can you guide more on this to resolve the issue.

Thanks in advance

milesstoetzner commented 2 years ago

I created a pull request to add my suggested fix, see https://github.com/puppetlabs/control-repo/pull/110. As you can see in the pull request a simple check is added in config_version.sh.

milesstoetzner commented 2 years ago

Closing this since https://github.com/puppetlabs/control-repo/pull/110 is merged