Git Product home page Git Product logo

puppetlabs-vcsrepo's Introduction

vcsrepo

Table of contents

  1. Overview
  2. Module Description - What the module does and why it is useful
  3. Setup - The basics of getting started with vcsrepo
  4. Usage - Configuration options and additional functionality
  5. Reference - An under-the-hood peek at what the module is doing and how
  6. Limitations - OS compatibility, etc.
  7. License
  8. Development - Guide for contributing to the module

Overview

The vcsrepo module lets you use Puppet to easily deploy content from your version control system (VCS).

Module description

The vcsrepo module provides a single type with providers to support the following version control systems:

Note: This module does not have the functionality to purge or delete local changes on agent run. Note: git is the only vcs provider officially supported by Puppet Inc. Note: Release v4.0.1 has been removed from the Puppet Forge and was officially re-released as version v5.0.0 as it contained a breaking change. Details available here

Setup

Setup requirements

The vcsrepo module does not install any VCS software for you. You must install a VCS before you can use this module.

Like Puppet in general, the vcsrepo module does not automatically create parent directories for the files it manages. Set up any needed directory structures before you start.

Beginning with vcsrepo

To create and manage a blank repository, define the type vcsrepo with a path to your repository and supply the provider parameter based on the VCS you're using.

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
}

Usage

Note: git is the only vcsrepo provider officially supported by Puppet Inc.

Git

Create a blank repository

To create a blank repository suitable for use as a central repository, define vcsrepo without source or revision:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
}

If you're managing a central or official repository, you might want to make it a bare repository. To do this, set ensure to 'bare':

vcsrepo { '/path/to/repo':
  ensure   => bare,
  provider => git,
}

Clone/pull a repository

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
  source   => 'git://example.com/repo.git',
}

To clone your repository as bare or mirror, you can set ensure to 'bare' or 'mirror':

vcsrepo { '/path/to/repo':
  ensure   => mirror,
  provider => git,
  source   => 'git://example.com/repo.git',
}

By default, vcsrepo will use the HEAD of the source repository's main branch. To use another branch or a specific commit, set revision to either a branch name or a commit SHA or tag.

Branch name:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
  source   => 'git://example.com/repo.git',
  revision => 'development',
}

SHA:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
  source   => 'git://example.com/repo.git',
  revision => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31',
}

Tag:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
  source   => 'git://example.com/repo.git',
  revision => '1.1.2rc1',
}

To check out a branch as a specific user, supply the user parameter:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
  source   => 'git://example.com/repo.git',
  revision => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31',
  user     => 'someUser',
}

To keep local changes while changing revision, use the keep_local_changes:

vcsrepo { '/path/to/repo':
  ensure             => present,
  provider           => git,
  source             => 'git://example.com/repo.git',
  revision           => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31',
  keep_local_changes => true,
  user               => 'someUser',
}

To keep the repository at the latest revision, set ensure to 'latest'. Note: keep_local_changes works by stashing local changes, switching the repo to the assigned revision and, finally, unstashing the local changes. It only comes into effect if the revision parameter is different from the local repo. This parameter DOES NOT delete/purge local changes by default on every run.

WARNING: This overwrites any local changes to the repository.

vcsrepo { '/path/to/repo':
  ensure   => latest,
  provider => git,
  source   => 'git://example.com/repo.git',
  revision => 'main',
}

To clone the repository but skip initializing submodules, set submodules to 'false':

vcsrepo { '/path/to/repo':
  ensure     => latest,
  provider   => git,
  source     => 'git://example.com/repo.git',
  submodules => false,
}

To clone the repository and trust the server certificate (sslVerify=false), set trust_server_cert to 'true':

vcsrepo { '/path/to/repo':
  ensure            => present,
  provider          => git,
  source            => 'git://example.com/repo.git',
  trust_server_cert => true,
}

To use a specific umask, set umask to the desired value (expressed as a string of octal numbers); note that changes to umask do not retroactively affect repo files created earlier under a different umask. This is currently only implemented for the git provider. If unspecified, this will use the umask of the puppet process itself.

Example to set shared group access:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
  source   => 'git://example.com/repo.git',
  revision => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31',
  umask    => '0002'
}

Use HTTP or HTTPS proxies

To use an HTTP or HTTPS proxy, set http_proxy to the proxy URL. This is currently only implemented for the git provider.

git uses libcurl, so proxying of HTTPS repo URLs uses the CONNECT method, which works with either an HTTP or HTTPS proxy (since libcurl 7.52.0).

Example to use an HTTPS proxy:

vcsrepo { '/path/to/repo':
  ensure     => present,
  provider   => git,
  source     => 'https://example.com/repo.git',
  http_proxy => 'https://proxy.example.com',
  revision   => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31',
}

Proxies can also be specified as a hash, keyed by remote, in which case vcsrepo will use the specified proxy for each remote that is used as a source (see the source parameter). For any source that does not have an http_proxy defined, no proxy will be used.

Example to use per-remote HTTPS proxies use a proxy for github but not for other remotes:

vcsrepo { '/path/to/repo':
  ensure     => present,
  provider   => git,
  source     => {
    origin => 'https://example.com/repo.git',
    github => 'https://github.com/example/repo.git',
  },
  http_proxy => {
    github => 'https://proxy2.example.com',
  },
  revision   => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31',
}

Specification of proxies this way affects remote operations performed by vcsrepo, but does not persist the proxy settings within either the per-user git configuration or the per-repo git configuration. This means that manual operations like git fetch and git pull within vcsrepo-managed working copies will not use proxies. If you need such operations to use proxies, then you can instead configure git on a per-user or per-repository basis. Example instructions for configuring git for a user are here: https://gist.github.com/evantoli/f8c23a37eb3558ab8765

For per-repository configuration, use --local instead of --global for git config commands (or edit the .git/config file within each repo working copy).

Use multiple remotes with a repository

In place of a single string, you can set source to a hash of one or more name => URL pairs:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => git,
  remote   => 'origin'
  source   => {
    'origin'       => 'https://github.com/puppetlabs/puppetlabs-vcsrepo.git',
    'other_remote' => 'https://github.com/other_user/puppetlabs-vcsrepo.git'
  },
}

Note: If you set source to a hash, one of the names you specify must match the value of the remote parameter. That remote serves as the upstream of your managed repository.

Connect via SSH

To connect to your source repository via SSH (such as 'username@server:…'), we recommend managing your SSH keys with Puppet and using the require metaparameter to make sure they are present before the vcsrepo resource is applied.

To use SSH keys associated with a user, specify the username in the user parameter:

vcsrepo { '/path/to/repo':
  ensure   => latest,
  provider => git,
  source   => 'ssh://[email protected]/repo.git',
  user     => 'toto', #uses toto's $HOME/.ssh setup
  require  => File['/home/toto/.ssh/id_rsa'],
}

To use SSH over a nonstandard port, use the full SSH scheme and include the port number:

vcsrepo { '/path/to/repo':
  ensure   => latest,
  provider => git,
  source   => 'ssh://[email protected]:7999/repo.git',
}

Important changes in version 5

Prior to version 5.0.0 StrictHostKeyChecking was implicitly disabled when using the identity parameter. This meant that ssh would automatically add new hosts to ~/.ssh/known_hosts, letting most connections succeed.

StrictHostKeyChecking has now been removed from the options passed to ssh which will result in ssh falling back to it's default, ask. This could cause puppet runs to fail.

To ensure a run completes successfully, you should add the hosts public key to the known_hosts before the vcsrepo resource is applied.

You can usually get the public key of an ssh host by running ssh-keyscan. Adding the result to your known_hosts file may look similar to this:

ssh-keyscan -t rsa github.com >> /home/me/.ssh/known_hosts

Once everything is configured, you can continue to manage your repositories with ssh.

vcsrepo { '/path/to/repo':
  ensure   => latest,
  provider => git,
  source   => '[email protected]:user/repo.git',
  identity => '/home/me/.ssh/id_rsa',
}

Bazaar

Create a blank repository

To create a blank repository, suitable for use as a central repository, define vcsrepo without source or revision:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => bzr,
}

Branch from an existing repository

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => bzr,
  source   => '/some/path',
}

To branch from a specific revision, set revision to a valid Bazaar revision spec:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => bzr,
  source   => '/some/path',
  revision => '[email protected]',
}

Connect via SSH

To connect to your source repository via SSH (such as 'bzr+ssh://...' or 'sftp://...,'), we recommend using the require metaparameter to make sure your SSH keys are present before the vcsrepo resource is applied:

vcsrepo { '/path/to/repo':
  ensure   => latest,
  provider => bzr,
  source   => 'bzr+ssh://bzr.example.com/some/path',
  user     => 'toto', #uses toto's $HOME/.ssh setup
  require  => File['/home/toto/.ssh/id_rsa'],
}

CVS

Create a blank repository

To create a blank repository suitable for use as a central repository, define vcsrepo without source or revision:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => cvs,
}

Checkout/update from a repository

vcsrepo { '/path/to/workspace':
  ensure   => present,
  provider => cvs,
  source   => ':pserver:[email protected]:/sources/myproj',
}

To get a specific module on the current mainline, supply the module parameter:

vcsrepo { '/vagrant/lockss-daemon-source':
  ensure   => present,
  provider => cvs,
  source   => ':pserver:[email protected]:/cvsroot/lockss',
  module   => 'lockss-daemon',
}

To set the GZIP compression levels for your repository history, use the compression parameter:

vcsrepo { '/path/to/workspace':
  ensure      => present,
  provider    => cvs,
  compression => 3,
  source      => ':pserver:[email protected]:/sources/myproj',
}

To get a specific revision, set revision to the revision number.

vcsrepo { '/path/to/workspace':
  ensure      => present,
  provider    => cvs,
  compression => 3,
  source      => ':pserver:[email protected]:/sources/myproj',
  revision    => '1.2',
}

You can also set revision to a tag:

vcsrepo { '/path/to/workspace':
  ensure      => present,
  provider    => cvs,
  compression => 3,
  source      => ':pserver:[email protected]:/sources/myproj',
  revision    => 'SOMETAG',
}

Connect via SSH

To connect to your source repository via SSH, we recommend using the require metaparameter to make sure your SSH keys are present before the vcsrepo resource is applied:

vcsrepo { '/path/to/repo':
  ensure   => latest,
  provider => cvs,
  source   => ':pserver:[email protected]:/sources/myproj',
  user     => 'toto', #uses toto's $HOME/.ssh setup
  require  => File['/home/toto/.ssh/id_rsa'],
}

Mercurial

Create a blank repository

To create a blank repository suitable for use as a central repository, define vcsrepo without source or revision:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => hg,
}

Clone/pull and update a repository

To get the default branch tip:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => hg,
  source   => 'http://hg.example.com/myrepo',
}

For a specific changeset, use revision:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => hg,
  source   => 'http://hg.example.com/myrepo',
  revision => '21ea4598c962',
}

You can also set revision to a tag:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => hg,
  source   => 'http://hg.example.com/myrepo',
  revision => '1.1.2',
}

To check out as a specific user:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => hg,
  source   => 'http://hg.example.com/myrepo',
  user     => 'user',
}

To specify an SSH identity key:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => hg,
  source   => 'ssh://[email protected]/myrepo',
  identity => '/home/user/.ssh/id_dsa1',
}

To specify a username and password for HTTP Basic authentication:

vcsrepo { '/path/to/repo':
  ensure              => latest,
  provider            => hg,
  source              => 'http://hg.example.com/myrepo',
  basic_auth_username => 'hgusername',
  basic_auth_password => 'hgpassword',
}

NOTE: The sensitive basic_auth_password can be deferred using the Deferred function on Puppet Master and enable to execute on agent.

vcsrepo { '/path/to/repo':
  ensure              => latest,
  provider            => hg,
  source              => 'http://hg.example.com/myrepo',
  basic_auth_username => 'hgusername',
  basic_auth_password => Deferred('sprintf', ['hgpassword']),
}

Connect via SSH

To connect to your source repository via SSH (such as 'ssh://...'), we recommend using the require metaparameter to make sure your SSH keys are present before the vcsrepo resource is applied:

vcsrepo { '/path/to/repo':
  ensure   => latest,
  provider => hg,
  source   => 'ssh://hg.example.com//path/to/myrepo',
  user     => 'toto', #uses toto's $HOME/.ssh setup
  require  => File['/home/toto/.ssh/id_rsa'],
}

Perforce

Create an empty workspace

To set up the connection to your Perforce service, set p4config to the location of a valid Perforce config file stored on the node:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => p4,
  p4config => '/root/.p4config'
}

Note: If you don't include the P4CLIENT setting in your config file, the provider generates a workspace name based on the digest of path and the node's hostname (such as puppet-91bc00640c4e5a17787286acbe2c021c).

Create/update and sync a Perforce workspace

To sync a depot path to head, set ensure to 'latest':

vcsrepo { '/path/to/repo':
  ensure   => latest,
  provider => p4,
  source   => '//depot/branch/...'
}

To sync to a specific changelist, specify its revision number with the revision parameter:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => p4,
  source   => '//depot/branch/...',
  revision => '2341'
}

You can also set revision to a label:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => p4,
  source   => '//depot/branch/...',
  revision => 'my_label'
}

Subversion

Create a blank repository

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => svn,
}

Check out from an existing repository

Provide a source pointing to the branch or tag you want to check out:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => svn,
  source   => 'svn://svnrepo/hello/branches/foo',
}

You can also designate a specific revision:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => svn,
  source   => 'svn://svnrepo/hello/branches/foo',
  revision => '1234',
}

####Checking out only specific paths

Note: The includes param is only supported when subversion client version is >= 1.6.

You can check out only specific paths in a particular repository by providing their relative paths to the includes parameter, like so:

vcsrepo { '/path/to/repo':
  ensure   => present,
  provider => svn,
  source   => 'http://svnrepo/hello/trunk',
  includes => [
    'root-file.txt',
    'checkout-folder',
    'file/this-file.txt',
    'folder/this-folder/',
  ]
}

This will create files /path/to/repo/file-at-root-path.txt and /path/to/repo/file/nested/within/repo.jmx, with folders /path/to/repo/some-folder and /path/to/repo/nested/folder/to/checkout completely recreating their corresponding working tree path.

When specified, the depth parameter will also be applied to the includes -- the root directory will be checked out using an empty depth, and the includes you specify will be checked out using the depth you provide.

To illustrate this point, using the above snippet (with the specified includes) and a remote repository layout like this:

.
├── checkout-folder
│   ├── file1
│   └── nested-1
│       ├── nested-2
│       │   └── nested-file-2
│       └── nested-file-1
├── file
│   ├── NOT-this-file.txt
│   └── this-file.txt
├── folder
│   ├── never-checked-out
│   └── this-folder
│       ├── deep-nested-1
│       │   ├── deep-nested-2
│       │   │   └── deep-nested-file-2
│       │   └── deep-nested-file-1
│       └── this-file.txt
├── NOT-this-file.txt
├── NOT-this-folder
│   ├── NOT-this-file.txt
│   └── NOT-this-one-either.txt
└── root-file.txt

With no depth given, your local folder /path/to/repo will look like this:

.
├── checkout-folder
│   ├── file1
│   └── nested-1
│       ├── nested-2
│       │   └── nested-file-2
│       └── nested-file-1
├── file
│   └── this-file.txt
├── folder
│   └── this-folder
│       ├── deep-nested-1
│       │   ├── deep-nested-2
│       │   │   └── deep-nested-file-2
│       │   └── deep-nested-file-1
│       └── this-file.txt
└── root-file.txt

And with a depth of files will look like this:

.
├── checkout-folder
│   └── file1
├── file
│   └── this-file.txt
├── folder
│   └── this-folder
│       └── this-file.txt
└── root-file.txt

####Use a specific Subversion configuration directory

Use the configuration parameter to designate the directory that contains your Subversion configuration files (typically, '/path/to/.subversion'):

vcsrepo { '/path/to/repo':
  ensure        => present,
  provider      => svn,
  source        => 'svn://svnrepo/hello/branches/foo',
  configuration => '/path/to/.subversion',
}

Connect via SSH

To connect to your source repository via SSH (such as 'svn+ssh://...'), we recommend using the require metaparameter to make sure your SSH keys are present before the vcsrepo resource is applied:

vcsrepo { '/path/to/repo':
  ensure   => latest,
  provider => svn,
  source   => 'svn+ssh://svnrepo/hello/branches/foo',
  user     => 'toto', #uses toto's $HOME/.ssh setup
  require  => File['/home/toto/.ssh/id_rsa'],
}

Reference

Type: vcsrepo

The vcsrepo module adds only one type with several providers.

For information on the classes and types, see the REFERENCE.md

Providers

Note: Not all features are available with all providers.

git - Supports the Git VCS.

Features: bare_repositories, depth, multiple_remotes, reference_tracking, ssh_identity, submodules, user

Parameters: depth, ensure, excludes, force, group, identity, owner, path, provider, remote, revision, source, user

bzr - Supports the Bazaar VCS.

Features: reference_tracking

Parameters: ensure, excludes, force, group, owner, path, provider, revision, source

cvs - Supports the CVS VCS.

Features: cvs_rsh, gzip_compression, modules, reference_tracking, user

Parameters: compression, cvs_rsh, ensure, excludes, force, group, module, owner, path, provider

hg - Supports the Mercurial VCS.

Features: reference_tracking, ssh_identity, user

Parameters: ensure, excludes, force, group, identity, owner, path, provider, revision, source, user

p4 - Supports the Perforce VCS.

Features: p4config, reference_tracking

Parameters: ensure, excludes, force, group, owner, p4config, path, provider, revision, source

svn - Supports the Subversion VCS.

Features: basic_auth, configuration, conflict, depth, filesystem_types, reference_tracking

Parameters: basic_auth_password, basic_auth_username, configuration, conflict, ensure, excludes, force, fstype, group, includes, owner, path, provider, revision, source, trust_server_cert

Features

Note: Not all features are available with all providers.

  • bare_repositories - Differentiates between bare repositories and those with working copies. (Available with git.)
  • basic_auth - Supports HTTP Basic authentication. (Available with hg and svn.)
  • conflict - Lets you decide how to resolve any conflicts between the source repository and your working copy. (Available with svn.)
  • configuration - Lets you specify the location of your configuration files. (Available with svn.)
  • cvs_rsh - Understands the CVS_RSH environment variable. (Available with cvs.)
  • depth - Supports shallow clones in git or sets the scope limit in svn. (Available with git and svn.)
  • filesystem_types - Supports multiple types of filesystem. (Available with svn.)
  • gzip_compression - Supports explicit GZip compression levels. (Available with cvs.)
  • include_paths - Lets you checkout only certain paths. (Available with svn.)
  • modules - Lets you choose a specific repository module. (Available with cvs.)
  • multiple_remotes - Tracks multiple remote repositories. (Available with git.)
  • reference_tracking - Lets you track revision references that can change over time (e.g., some VCS tags and branch names). (Available with all providers)
  • ssh_identity - Lets you specify an SSH identity file. (Available with git and hg.)
  • user - Can run as a different user. (Available with git, hg and cvs.)
  • p4config - Supports setting the P4CONFIG environment. (Available with p4.)
  • submodules - Supports repository submodules which can be optionally initialized. (Available with git.)

Limitations

Git is the only VCS provider officially supported by Puppet Inc. Git with 3.18 changes the maximum enabled TLS protocol version, this breaks some HTTPS functionality on older operating systems. They are Enterprise Linux 5 and OracleLinux 6.

The includes parameter is only supported when SVN client version is >= 1.6.

For an extensive list of supported operating systems, see metadata.json

Response to CVE-2022-24765

The vulnerability described in this CVE could impact users working on multi-user machines. A malicious actor could create a .git directory above the current working directory causing all git invocations to occur outside of a repository to read its configuration.

For a more in-depth description of this vulnerability, check out this blog post.

Fixes were released in Git versions 2.35.2 and 1:2.25.1-1ubuntu3.4 respectively.

VCSRepo users were impacted when running newer versions of Git and managing repositories that were owned by a user or group that differed from the user executing Git.

For example, setting the owner parameter on a resource would cause Puppet runs to fail with a Path /destination/path exists and is not the desired repository. error.

Impacted users are now advised to use the new safe_directory parameter on Git resources. Explicitily setting the value to true will add the current path specified on the resource to the safe.directory git configuration for the current user (global scope) allowing the Puppet run to continue without error.

Safe directory configuration will be stored within the system wide configuration file /etc/gitconfig.

License

This codebase is licensed under the Apache2.0 licensing, however due to the nature of the codebase the open source dependencies may also use a combination of AGPL, BSD-2, BSD-3, GPL2.0, LGPL, MIT and MPL Licensing.

Development

Puppet Inc. modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can't access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve.

We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.

You can read the complete module contribution guide on the Puppet documentation site.

puppetlabs-vcsrepo's People

Contributors

adrianiurca avatar bigpreshkt avatar binford2k avatar bmjen avatar chelnak avatar cyberious avatar daianamezdrea avatar david22swan avatar davids avatar disha-maker avatar eimlav avatar eputnam avatar gspatton avatar hunner avatar jamtur01 avatar jordanbreen28 avatar justinstoller avatar lionce avatar lukasaud avatar malikparvez avatar mpdude avatar p4paul avatar pmcmaw avatar rajat-puppet avatar ramesh7 avatar sanfrancrisko avatar sheenaajay avatar sodabrew avatar sp-ricard-valverde avatar tphoney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppetlabs-vcsrepo's Issues

working_copy_exists? for svn throws an error

Just moved from the 0.1.2 to 0.2.0 release and am now seeing errors when trying to create a working copy; svnlook is consistently throwing an error when checking to see if the working copy already exists:

Error: /Vcsrepo[/path/to/working/copy]: Could not evaluate: Execution of '/usr/bin/svnlook uuid /path/to/working/copy' returned 1: svnlook: Can't open file '/path/to/working/copy/format': No such file or directory

The errors are originating with the following method defined in the svn provider:

  def working_copy_exists?
    if File.directory?(@resource.value(:path))
      # :path is an svn checkout
      return true if File.directory?(File.join(@resource.value(:path), '.svn'))
      # :path is an svn server
      return true if svnlook('uuid', @resource.value(:path))
    end
    false
  end

Does svnlook's behavior vary across platforms? I'm running this on the puppet labs ubuntu 12.04 LTS.

Repo gets detached

We have constant issues with the repo getting into a detached state somehow and receive these error messages:

err: Vcsrepo[-------]: Could not evaluate: Execution of '/bin/su tomcat -c git rev-parse origin/(detached from 84bfb1f)' returned 1: bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `git rev-parse origin/(detached from 84bfb1f)'

I have the vcsrepo configured as such:

  vcsrepo { "$target":
    ensure => latest,
    provider => git,
    source => 'ssh://git@*************/deployer.git',
    user => 'tomcat',
    revision => 'master',
  }

Can't authenticate to private repositories via HTTPS

Describe the Bug

Trying to copy a repo via HTTPS where an authentication to the repository is required fails.
The error message:

Error: Execution of 'git clone --branch Preview https://xxxxxx/xxxxxxx/_git/xxx /var/www/' returned 128: Cloning into '/var/www/'...
fatal: could not read Username for 'https://xxxxxx': No such device or address

Expected Behavior

Define base_auth_(username|password) and git should be able to fetch the repository.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Try to load a git repository over an HTTPS, that is protected via user authentication.
  2. Provide both base_auth_(username|password).
  3. Get the error.

Environment

  • vcsrepo 5.2.0
  • Puppet 7.18.0
  • Debian 11
  • Azure Devops Server (in a git environment)

Additional Context

  • Similar to #97, but couldn't be resolved by providing a .netrc file to the user set via the "user" variable.
  • Providing username and password by adding them in the https://username:[email protected] syntax does not solve the issue.

Change in v5.2.0 causes "Could not evaluate: undefined method `dir' for nil:NilClass" on Windows

Describe the Bug

Since the release of v5.2.0, when using the vcsrepo module on Windows customer gets the error "Could not evaluate: undefined method `dir' for nil:NilClass" on every run. Problem does not occur with v5.1.0 of this module.

Expected Behavior

Repository should be handled without error

Steps to Reproduce

Error is consistent using module as follows

class profile::vcsrepotest {
  vcsrepo { "C:/admkrdev.ide/Jobs":
    ensure   => latest,
    provider => git,
    source   => '[email protected]:aaronhilton0/control-repo.git',
    identity => 'C:/keys/id_rsa',
  }
}

Environment

  • Windows Server 2019
  • Puppet Enterprise 2021.5

Additional Context

Currently affecting customer on ticket 48952

SSH identity with custom user

Describe the Bug

I am trying to clone/pull repository with custom user + custom ssh identity, but it returns

Error: Execution of 'git clone [email protected]:root/zones.git /var/lib/powerdns/zones.master.d' returned 128: Cloning into '/var/lib/powerdns/zones.master.d'...
Host key verification failed.
fatal: Could not read from remote repository.

But if I try same with default user (root) it works fine, checked permissions, custom user can access id_rsa file. I suspect when custom user used, identity parameter is ignored because when I use non existing key file with default user it returns "Warning: Identity file /opt/id_rsa not accessible: No such file or directory." but with custom user it does not return any warning.

Provider svn does not support features multiple_remotes; not managing attribute remote

After updating to the newer vcsrepo, test runs show an interesting new message about svn and remotes. Things appear to work fine, however.

$ cat modules/vcsrepo/Modulefile 
name 'puppetlabs/vcsrepo'
version '0.1.1'

# puppet agent --test --logdest=/dev/null --noop
[snip]
info: Caching catalog for localhost.localdomain
info: /Vcsrepo[reponame]: Provider svn does not support features multiple_remotes; not managing attribute remote
info: Applying configuration version '1234567890'

Error "Invalid parameter provider"

Hello,

I have the following configuration:

vcsrepo { "$directory" :
    ensure => latest,
    provider => git,
    source => "[email protected]:example/project.git",
    revision => "$revision",
    user => "$user",
    require => Class['::nginx'],
}

And when I run puppet agent on my node, I get this error:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter provider at /var/lib/puppet/modules/project/manifests/init.pp:21 on node mynode.example.com

This error is repeated in the puppetmaster's log as well.

I've found a few old mentions of similar issues (http://projects.puppetlabs.com/issues/17814) but I can't find any definitive solutions.

Based on the hints in the above link, I restarted the puppet master, but that didn't solve the problem. I did verify that the git.rb file is in the puppet repository.

Both the master and slave are running Puppet 3.4.2

Any help would be appreciated.

New release to forge.puppetlabs.com

The latest release of this module in forge.puppetlabs.com is over a year old. There has been quite a bit of improvement to the module since then, for instance support for #latest? for the Git provider.

Could you release a new version to forge.puppetlabs.com, please? That way it is easier to get an up to date version by using the puppet-module tool.

Lets do a release!

Hey,

As there's a ton of commits and work that's gone into this recently, do you think we're ready for a release @sodabrew?

git provider fails when attempting to change branches

When attempting to change the checked out branch of an existing repo, the git provider fails as git rev-parse <ref> fails on branch names that have not been fetched into the local repo.

eg.

Error: /Stage[main]/Portal::Source/Vcsrepo[/www/rails/portal]: Could not evaluate: Execution of '/bin/su root -c git rev-parse develop' returned 128: fatal: ambiguous argument 'develop': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
develop

Duplicate Error whenever installing vcsrepo module in masterless config

Describe the Bug

I am installing the vcsrepo module via r10k in a masterless machine. Whenever I install the repo, during compilaton but before the puppet code is run, I get this error:

# puppet apply /etc/puppet Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Vcsrepo[/tmp/vcstest/p4_client_root] is already declared at (file: /etc/puppet/modules/vcsrepo/examples/p4/create_client.pp, line: 1); cannot redeclare (file: /etc/puppet/modules/vcsrepo/examples/p4/delete_client.pp, line: 1) (file: /etc/puppet/modules/vcsrepo/examples/p4/delete_client.pp, line: 1, column: 1) on node ip-10-251-0-196.ec2.internal

I noticed that the issue is the "examples/p4" folder which declares the

vcsrepo { '/tmp/vcstest/p4_client_root': twice, which is causing the error.

Here's the reference to the code in question:

https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/main/examples/p4/create_client.pp
https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/main/examples/p4/delete_client.pp

Expected Behavior

The module should install and run without issue since this is just a module installation from source

Steps to Reproduce

Steps to reproduce the behavior:

  1. Add mod 'puppetlabs-vcsrepo', '5.2.0' to the Puppetfile
  2. Run r10k puppetfile install --puppetfile /etc/puppet/Puppetfile --moduledir /etc/puppet/modules to install the module
  3. Run puppet apply /etc/puppet

Environment

  • Version 5.5.22
  • Debian 11 (bullseye)

Additional Context

I have commented out all invocations of vcsrepo in my code and have isolated the issue to the module install

version 5.0.0 of the module ignores identity attribute on EL7

Describe the Bug

Upgrading vcsrepo from 4.0.0 to 5.0.0 results in the identity attribute not being used on EL7. Looks to be related to this issue https://tickets.puppetlabs.com/browse/MODULES-11111.

Expected Behavior

identity should be usable on all OSes supported by the module

Steps to Reproduce

Steps to reproduce the behavior:
Install puppetlabs-vcsrepo 5.0.0

Use identity in a vcsrepo declaration:

  vcsrepo { '/tmp/repository':
    ensure   => present,
    provider => git,
    source   => 'git@host:repo.git',
    identity => '/root/.ssh/id_key',
  }

Compare results on different machines:

Centos7 (git version 1.8.3.1)

Cloning into '/tmp/repository'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights

Ubuntu 20.04 (git version 2.25.1)

�[0;36mDebug: Executing: '/usr/bin/git config -l'�[0m
�[0;36mDebug: Executing: '/usr/bin/git submodule update --init --recursive'�[0m
�[mNotice: /Stage[main]/Main/Node[nodel]/Vcsrepo[/tmp/repository]/ensure: created�[0m

Environment

  • vcsrepo version 5.0.0
  • Platform EL7

Additional Context

The issue is not reproducible with vcsrepo v 4.0.0

Git validate gpg signature

Use Case

GPG signatures on git commits are a great way to ensure the code being checked out hasn't been tampered with. This is particularly true for automated checkouts.

Describe the Solution You Would Like

It would be nice for certain repos to be able to set --verify-signatures so that only correctly signed commit can be checked out.

Describe Alternatives You've Considered

There doesn't seem to be a great way to work around this....

Additional Context

https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work

Basic auth password with parenthesis fails svn commands

Describe the Bug

I use the svn provider to check out a repository. The password passed via basic_auth_password contains a "(" character.

Expected Behavior

The repository gets checked out correctly.

Steps to Reproduce

Steps to reproduce the behavior:
Configure a vcsrepo like this:

  vcsrepo { "/checkout/folder":
    ensure              => latest,
    provider            => svn,
    source              => <YourURL>,
    basic_auth_username => user,
    basic_auth_password => "password(fails)",
  }

The provider tries to call svn for getting the latest and the current revision. Since each call fails, the variables contain nil. The user will see the following misleading error on the console:
/Stage[main]/Vcsrepo[/checkout/folder] | Could not evaluate: undefined method >=' for nil:NilClass`

Environment

  • Version 5.0.0
  • Platform 20.04

Error Analysis

The error shown above stems from the latest? function in line 79 of svn.rb. The issue MODULES-10659 brought me on track, since it has a similar background. It is a follow up issue as the previous calls of latest and revision returned nil, since the svn commands fail. It took me a while to find the issue, but it seems that ruby in the background just opens a shell to execute its commands. When you add :combine => true for the svn_wrapper you will register the error from svn which gets consumed by the ruby code otherwise:

Error: /Vcsrepo[/checkout/folder]: Could not evaluate: Execution of 'svn --non-interactive --username user --password password(fails) --no-auth-cache info' returned 2: sh: 1: Syntax
error: "(" unexpected

You will get the same error trying to execute the command on the shell due to shell expansion.

Workaround

The issue can be circumvented by just adding the quotes when passing the text from puppet like this:
basic_auth_password => "\"password(fails)\"",
Another possibly not so intelligent workaround is to downgrade to version 2.2.0, which obviously used another mechanism to call svn and does not show the error. I was unable to reproduce why it works with that version since I was unable to find the origin of the svn function used back then instead of Puppet::Util::Execution.execute, which is used nowadays.

Suggested Fix

Escape the password when pushing it to the args list in the buildargs function.

Feature request for logoutput

It would be nice to have the option whether or not to log output, like the Exec resource type does. That avoids passwords being logged in puppet reports/logging/etc.

Detatched head state when behind origin/<BRANCH>

We are seeing repos that are supposed to be the latest of a given branch@origin going into a detatched head state. When first doing a puppet run the checkout is perfect. The correct branch is checked out and all is well.

However if there are any commits to origin/ then after the next puppet-run the repo is left without a branch set. If we manually do

git checkout <BRANCH>
git merge --ff-only origin/<BRANCH>

Then the repo is again back to where it should be.

The resources are defined like so:

vcsrepo { "$checkoutroot/testing":
  provider => git,
  ensure   => latest,
  source   => '[email protected]:foobar/<REPO>.git',
  identity => "${ssh_priv_key}",
  revision => '<BRANCH>',
  force    => true,
}

Substitute for a branch that exists at origin. The branch at origin that we in our case want to 'lock' to is 'develop', however I do not believe that the name of this matters. Having "force => true" in or not does not affect outcome.

We are using vcsrepo at 8356fc9, latest on master at the moment.

Does not install VCS software

The vcsrepo module does not install version control software.The documentation should cover that the software should be installed prior to vcsrepo.

(I use our own git module to install git, but use vcsrepo to handle repositories)

Debian 9 empty service_name

Describe the Bug

When running acceptance tests, Debian 9 is timing out and throwing the following error empty service_name.

Expected Behavior

service_name to be set and acceptance tests to run on the machine.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Go to https://github.com/puppetlabs/puppetlabs-vcsrepo/runs/7324094720?check_suite_focus=true
  2. Confirm test suite times out and throws empty service_name at the acceptance test stage.

Environment

  • Version puppet6-nightly, puppet7-nightly
  • Platform Debian9

Additional Context

N/A

How to "checkout" at a tag?

I would like to clone a git repo, and "checkout" a tag as a named branch. I can do this manually with exec, but I'd prefer to use vcsrepo if possible.

Does vcsrepo currently support this (e.g., with revision => "<tag>")?

Broken Git checkouts

err: /Stage[main]//Vcsrepo[/home/p2pool/p2pool]/ensure: change from present to latest failed: Execution of '/bin/su p2pool -c git checkout -b a32b6efd20124352d7a74047f0d95283b8e5c09c --track origin/a32b6efd20124352d7a74047f0d95283b8e5c09c' returned 128: fatal: git checkout: updating paths is incompatible with switching branches.

Did you intend to checkout 'origin/a32b6efd20124352d7a74047f0d95283b8e5c09c' which can not be resolved as commit?

ensure => latest now broken after CVE-2022-24765 patch.

Describe the Bug

After applying the patch for git on both ubuntu 18.04 and ubuntu 20.04 machines, puppet runs now fail.

change from 'absent' to 'latest' failed: Path /destination/path exists and is not the desired repository. (corrective)

Expected Behavior

Successful puppet run by cloning the desired repo to the desired location

Steps to Reproduce

update git to 1:2.25.1-1ubuntu3.3 on 20.04 and rerun puppet.

Environment

  • Version v4.0.0
  • Platform Ubuntu 20.04, and Ubuntu 18.04

bzr: "owner" ignored

The bzr backend never calls set_owner, so files are owned by root if "owner=..." given

Add `ensure => mirror` for git

I'm considering adding ensure => mirror for keeping bare repositories up-to-date.

  1. is the :mirror the best name for it?
  2. does anyone have any objections for such feature?

Only notify on change

I have a checkout and whenever a file changes a command should be executed. Unfortunately the command is executed everytime, because vcsrepo notifies the exec regardless of whether changes occurred or not.

Example:

vcsrepo { "${app_root}/checkout":
    ensure   => present,
    provider => 'git',
    source   => $source,
    user     => $user,
    revision => $revision,
    require  => File[$app_root],
  }
exec { 'test-vcsrepo':
   command     => 'echo "========\n\n\n\nTHIS SHOULD NOT RUN \n\n\n\n\n======="; exit 1;',
   refreshonly => true,
   subscribe   => Vcsrepo["${app_root}/checkout"],
   user        => 'deployment',
 }

Each vcsrepo parameter stays the same. It executes all checks each puppet agent run, but also notifies test-vcsrepo each run. I would love to see it behave like file or similar resources, that only notify on change.

Execution of 'git config --global --unset safe.directory /tmp/test' returned 5

Describe the Bug

Execution of 'git config --global --unset safe.directory /tmp/test' returned 5

Expected Behavior

No error

Environment

  • Vcsrepo 5.2.0
  • Git 2.25.1
  • Ubuntu 20.04

Additional Context

The new functionality regarding git safe directories (#549) inside the git provider tries to always unset the directory, even when it has not been set before. But the git config command will return 5 when that occurs:

https://git-scm.com/docs/git-config
This command will fail with non-zero status upon error. Some exit codes are: ... you try to unset an option which does not exist (ret=5),

upgrade to 5.2.0 breaks puppet server and nodes

I upgraded this module to 5.2.0 on a test puppet server and now a puppet run on the server is returning this:

Error: Facter: error while resolving custom facts in /opt/puppetlabs/puppet/cache/lib/facter/vcsrepo_svn_ver.rb: /opt/puppetlabs/puppet/cache/lib/facter/vcsrepo_svn_ver.rb:15: syntax error, unexpected keyword_rescue, expecting keyword_end
  rescue StandardError
        ^
/opt/puppetlabs/puppet/cache/lib/facter/vcsrepo_svn_ver.rb:18: syntax error, unexpected keyword_end, expecting end-of-input

I did restart the puppetserver service before, just to make sure.

The puppet nodes that use vcsrepo have more errors, but probably the root cause is the error above. This is on an Ubuntu 18.04 puppet master with packages from puppetlabs.

Svn provider does not correctly compare revision to latest

Describe the Bug

Svn provider performs a string comparison against integer revisions resulting in incorrectly saying it is as the latest revision when it is not. eg. revision 99 > 100

Expected Behavior

Version 100 should be > 99 resulting in an update to latest.

Steps to Reproduce

  vcsrepo { 'my svn repo':
    ensure              => latest,
    path                => '/opt/mysvnrepo',
    provider            => svn,
    source              => 'https://subversion.domain.com/svn/myrepo',
    basic_auth_username => 'myuser',
    basic_auth_password => Sensitive('mypass'),
  }

svn info | grep '^Revision'
Revision: 99

Latest revision in svn repo is >= 100

Run puppet - no change.

Environment

  • Version vcsrepo 5.0.0
  • Platform - RedHat 7

Additional Context

https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/main/lib/puppet/provider/vcsrepo/svn.rb#L81
should simply use the to_i
(revision.to_i >= latest.to_i) && (@resource.value(:source) == source)

Error "Could not evaluate: undefined method `strip' for nil:NilClass" while checking out latest cvs

When checking out "latest" revision with provider cvs, I get the an error. My manifest looks like:

vcsrepo { '/usr/local/share/test':
ensure => 'latest',
provider => 'cvs',
source => ':extssh:cvstransfer@cvsserver:/path/to/repo',
module => [ 'test1', 'test2', 'test3' ],
#module => 'test1',
}

puppet outputs:
info: Applying configuration version '1384163061'
err: /Vcsrepo[/usr/local/share/test]: Could not evaluate: undefined method `strip' for nil:NilClass
notice: Finished catalog run in 40.31 seconds

It's the same whether the module is a string or an array.

Automatically accept GitHub's and private Git Lab's server keys

I'm using ssh forwarding in order to clone private repos in Vagrant using the host's SSH keys. For some reason, my vcsrepo steps were failing until I wrote an exec { ... 'git -T [email protected] -o StrictHostKeyChecking=no; echo Success' ... } step as a requirement for my vcsrepo steps in my Puppet script.

Is there a way for Puppet users to give command line flags to the git command that vcsrepo builds?

In the future, could vcsrepo automatically accept server keys?

Support changing source attribute for svn

At least the svn provider does not deal with a changing source attribute at all (for example when the server is moving or the repository URL should point to a different branch). It still points out the old repository when it has already been checked out.

The corresponding command is "svn switch OLDURL NEWURL".

Potential support for depth on git checkouts? Or an options hash?

We use VCSrepo on servers, and would like to have the ability to check them out with a --depth 1.

Could we add a options hash, or something?

Or just add support directly to the git checkout. It doesn't look like there's a good way to add a single parameter to one VCS without adding it to the others, though..

SVN provider should check for '^Revision:' and not '^Last Changed Rev:'

This subversion repository revision:

[root@host somedir]# svn info
Path: .
URL: http://svn/someapp/trunk
Repository Root: http://svn/someapp
Repository UUID: 3086d4a2-aef2-4587-acb0-e7a012cffd39
Revision: 480863
Node Kind: directory
Schedule: normal
Last Changed Author: root
Last Changed Rev: 480862
Last Changed Date: 2012-11-12 12:35:48 -0600 (Mon, 12 Nov 2012)

causes this Vcsrepo code to constantly update (over and over)

vcsrepo { '/some/dir':
  ensure              => 'present',
  provider            => 'svn',
  source              => 'http://svn/someapp/trunk',
  revision            => '480863',
}

Mon Nov 26 10:37:49 -0700 2012 /Vcsrepo[/some/dir]/revision (notice): revision changed '480862' to '480863'

The code in lib/puppet/provider/vcsrepo/svn.rb should be changed from svn(*args)[/^Last Changed Rev:\s+(\d+)/m, 1] to svn(*args)[/^Revision:\s+(\d+)/m, 1].

GIT: Provide ability to override remote name when cloning and to provide additional remotes

I'm using this module for a development workstation where GithubFlow is the popular form of development. In this case, we have 2 remotes (named: upstream and fork).

I'm happy to work on this, but would like some direction on how the resource definition should look. I was was thinking of the following

vcsrepo { "awesome-project":
  ensure => present,
  path => "/opt/src/awesome-project",
  source => "git://github.com:awesome-project/awesome-project.git",
  remote => "upstream",
  provider => "git",
  remotes => { "fork" => "[email protected]:me/awesome-project.git" },
}

Thoughts?

Override local changes

Hello,

i am using vcsrepo to keep my modules up to date.

    vcsrepo { '/etc/puppet/modules/development':
        ensure   => latest,
        provider => git,
        source   => 'git://example.net/puppet.git',
        revision => 'development',
    }

    vcsrepo { '/etc/puppet/modules/testing':
        ensure   => latest,
        provider => git,
        source   => 'git://example.net/puppet.git',
        revision => 'testing',
    }

    vcsrepo { '/etc/puppet/modules/production':
        ensure   => latest,
        provider => git,
        source   => 'git://example.net/puppet.git',
        revision => 'master',
    }

This works fine, but i am wondering how i can override local changes. For example:

root@puppet:/etc/puppet/modules/production/lvm# git status
# On branch master
nothing to commit (working directory clean)
root@puppet:/etc/puppet/modules/production/lvm# git rm  README.markdown 
rm 'README.markdown'
root@puppet:/etc/puppet/modules/production/lvm# git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    README.markdown
#
root@puppet:/etc/puppet/modules/production/lvm# puppet agent --test
Ignoring --listen on onetime run
Info: Retrieving plugin
Info: Caching catalog for puppet.credativ.lan
Info: Applying configuration version '1354290723'
Finished catalog run in 6.87 seconds
root@puppet:/etc/puppet/modules/production/lvm# git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    README.markdown
#

Off course vcsrepo did not changed anything, because there are no new commits. But it would be great, if vcsrepo could undo the uncommited local changes, because i did not want anyone to mess with my modules directory.

Best regards, Dennis

/usr/bin/git rev-parse HEAD' returned 128: fatal: ambiguous argument 'HEAD'

This is what I get when trying to setup a git repo, branch "release":

    vcsrepo { "$website_path":
        ensure => present,
        provider => git,
        source => $website_repo,
        revision => 'release',
    }
/Stage[main]/Website-profile/Vcsrepo[/var/www/html] (err): Could not evaluate: Execution of '/usr/bin/git rev-parse HEAD' returned 128: fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
HEAD

puppetlabs-vcsrepo (v0.2.0)
git-1.7.1-3.el6_4.1.x86_64
puppet-3.3.2-1.el6.noarch

vcsrepo module not taking non-committed changes

Describe the Bug

VCSRepo
Module Version: 5.2.0
Puppet Version: 7.12.1
The customer is trying to use the vcsrepo module with the git as the version control system.

Desired Behavior:

Puppet does not recognize changes that were not staged or committed, Git recognizes files that have been modified, added, removed, but have not been staged or committed, but puppet does not seem to recognize this scenario either.

I tried to simulate the customer issue in my lab environment and i am able to reproduce the issue details have been provided in the ticket on what steps i have taken to reproduce.

Expected Behavior

Puppet is also not recognizing changes that were not staged or committed, Git recognizes files that have been modified, added, removed, but have not been staged or committed, but puppet does not seem to recognize this scenario either.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Installed the vcsrepo module
  2. copied the following code in the site.pp to enable the git

`
node 'testnode-5a3375-0.us-west1-c.c.customer-support-scratchpad.internal' {

 
vcsrepo { '/var/tmp/testrepo':
ensure => present,
provider => git,
source=>'[email protected]:kksubbu72/testcontrol.git',
keep_local_changes => false,
revision=>'StagingEnv',
}

`
3) I was able to clone the repository after running the puppet agent -t
4) I created some arbitrary file in the data folder of the local repo, Git status seems to be recognising the file by the name test.html got modified whereas, the puppet agent run coudn't recognize the same

`
root@0f:/var/tmp/testrepo/data# git status

On branch StagingEnv
Your branch is up to date with 'origin/StagingEnv'.
 
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
 
modified: test.html
 
no changes added to commit (use "git add" and/or "git commit -a")
root@0f:/var/tmp/testrepo/data# puppet agent -t
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for testnode-5a3375-0.us-west1-c.c.customer-support-scratchpad.internal
Info: Applying configuration version 'pe-server-1983ee-0-production-80329c0a2d4'
Notice: Applied catalog in 0.03 seconds
root@0f:/var/tmp/testrepo/data# git status
On branch StagingEnv
Your branch is up to date with 'origin/StagingEnv'.
 
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
 
modified: test.html
 
no changes added to commit (use "git add" and/or "git commit -a")
`
5) I tried the set the variable keep_local_changes to be false and true and still the puppet agent -t didn't resolve the pending commit in the local repo.

Environment

VCSRepo
Module Version: 5.2.0
Puppet Version: 7.12.1

Additional Context

The customer expects that the module changes were not respected by puppet run.
Please review the changes and suggest if my understanding is correct as well as per the lab reproduction steps shared here.

couldn't find login name -- expanding `~' since 5.1.0 with Centos 7

Describe the Bug

Since 5.1.0 release with Centos 7 hosts, the agent fails after puppet agent is automatically executed from the SystemD service. No issue is spotted when puppet agent is executed manually.

The following message is raised when the bug occurs: Could not evaluate: couldn't find login name -- expanding ~'`

Expected Behavior

Puppet recipes should not fail when used

Steps to Reproduce

  1. Let SystemD run puppet agent with VCSRepo 5.1.0
  2. Check reports with Puppetboard

Environment

  • Version: 5.1.0
  • Platform: Centos 7.9 with Puppet Agent 6.27

Additional Context

This is probably the same problem as mentioned here and was addressed in this PR.

TLDR: it looks like Ruby has an issue with Dir.home because it will try expanding ~, but it will fail when HOME is not set, which is the case when running from a SystemD service.

git clone doesn't work if destination path already exists.

Hi,

If I do a git clone to an existing directory with files , vcsrepo cloning throwing an error says files exists. Is it possible to implement support for git pull in vcsrepo or any work around ?

Config

Checkout the varnish config repo

vcsrepo { "/etc/varnish":
ensure => present,
provider=> git,
source => "git@git:varnishconf.git"
}

Logs

Sep 6 11:33:53 node9 puppet-agent[9055]: (/Stage[main]/Varnish/Vcsrepo[/etc/varnish]/ensure) change from absent to present failed: Execution of '/usr/bin/git
clone git@git:varnishconf.git /etc/varnish' returned 128: fatal: destination path '/etc/varnish' already exists and is not an empty directory.

Include attribute named "gitpath"

We are using git for windows and it would be nice if you can include a new attribute under the VcsRepo resource type that indicates where the git.exe is located. For now i have to handle this using environment variable %PATH%.

revision => 'v1.3.4' is executed on every puppet run

I'm running into idempotency problems with the following code change to puppet-gitlab

We have revision => '1.7.9' (which is a tag), with ensure => 'present', yet it's being executed on every puppet run:

igalic@git01 ~ % sudo puppet agent -t 
[sudo] password for igalic: 
Info: Retrieving plugin
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb
Info: Loading facts in /var/lib/puppet/lib/facter/concat_basedir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/has_group_libvirtd.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
Info: Loading facts in /var/lib/puppet/lib/facter/has_libvirtd.rb
Info: Caching catalog for git01.esat
Info: Applying configuration version '1386881409'
Notice: /Stage[main]/Gitlab::Package/Vcsrepo[/home/git/gitlab-shell]/revision: revision changed '9e00fb4078ca8a168687f876c1f6a98198a68155' to 'v1.7.9'
Notice: Finished catalog run in 10.65 seconds
sudo puppet agent -t  7,51s user 2,16s system 45% cpu 21,312 total
2 igalic@git01 ~ % sudo puppet agent -t 
Info: Retrieving plugin
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb
Info: Loading facts in /var/lib/puppet/lib/facter/concat_basedir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/has_group_libvirtd.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
Info: Loading facts in /var/lib/puppet/lib/facter/has_libvirtd.rb
Info: Caching catalog for git01.esat
Info: Applying configuration version '1386881409'
Notice: /Stage[main]/Gitlab::Package/Vcsrepo[/home/git/gitlab-shell]/revision: revision changed '9e00fb4078ca8a168687f876c1f6a98198a68155' to 'v1.7.9'
Notice: Finished catalog run in 8.95 seconds
sudo puppet agent -t  7,13s user 2,06s system 61% cpu 14,987 total
2 igalic@git01 ~ % 

Git: Short SHA performance

Use Case

There is also an optimisation if the cloned repo is at the correct revision: https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/main/lib/puppet/provider/vcsrepo/git.rb#L529-L532 introduced in #380

But this only works with full SHAs.

When the SHA isn't an exact match, a git fetch is run, which can potentially be slow for large repos

Describe the Solution You Would Like

git rev-parse HEAD is used to get the current commit for use in comparison, which returns the full sha.

Could that command change to git rev-parse --short={@resource.value(:revision).length} HEAD for the comparison?

This would then match, and not bother with the rest of the get_revision function.

Massive failure for test cases across all supported OS

Describe the Bug

VCSRepo seems to have crashed and has been burning for over 3 months now. There is, approximately, 70 (out of a total of 128 tests) test case errors for every OS that we support. Some outstanding error messages include:

Error: /Stage[main]/Main/Vcsrepo[/tmp/vcsrepo/testrepo_blank_with_revision_repo]/ensure: change from 'absent' to 'present' failed: Could not set 'present' on ensure: No such file or directory @ dir_s_mkdir - /tmp/vcsrepo/testrepo_blank_with_revision_repo (file: /root/manifest_20220516_3080_kmgh6q.pp, line: 1)

and

Error: Could not set 'bare' on ensure: No such file or directory @ dir_s_mkdir - /tmp/vcsrepo/testrepo_bare_repo (file: /root/manifest_20220516_3080_sla9tq.pp, line: 1)

Expected Behavior

Nightly runs should return all OS with a green pass.

Steps to Reproduce

Issue is reproduced every day in our nightly run system. Alternatively, it probably can be replicated locally by running acceptance testing in any OS machine.

Environment

  • Puppet version: Both 6 and 7
  • Platform: All supported OS

Additional Context

Last correct nightly run seems to be around early October 2021. After that date, we are missing nightly logs for about 1-2 months. The next puppet nightly run is around early February, on what seems to be a pdkSync to remove centOS 6 from supported OS.

owner/group not set if repo already exists

puppetlabs-vcsrepo (v0.2.0)

If you clone a repo:

vcsrepo { "/path/to/repo":
    ensure => present,
    provider => git,
    source => "git://example.com/repo.git"
}

And then add a owner:group:

vcsrepo { "/path/to/repo":
    ensure => present,
    provider => git,
    source => "git://example.com/repo.git",
    owner => "someuser",
    group => "someuser",
}

The original ownership of the folder structure remains. It appears that the ownership is only set on the initial creation/clone of the repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.