1

I've written a Puppet module to install Git on Windows. The Puppet Master is Linux.

Is it possible to write a Puppet manifest to clone a GitHub repo using just puppet resources (i.e. without a script or exec)?

This is a private repo, so the solution needs to include secure credentials.

Peter Souter
  • 5,110
  • 1
  • 33
  • 62
BaltoStar
  • 8,165
  • 17
  • 59
  • 91
  • Not sure why you have that limitation. I didn't support windows system, and can only recommend the forge modules for linux: [puppetlabs/vcsrepo](https://forge.puppetlabs.com/puppetlabs/vcsrepo) – BMW Jun 06 '15 at 11:43
  • As shown puppetlabs/vcsrepo actually does work on Windows, it's just not officially supported :) – Peter Souter Jun 10 '15 at 15:59

1 Answers1

6

It is indeed possible on Windows! You can use the puppetlabs-vcsrepo module

Example of it in action Screenshot using a Windows 2012R2 machine in Virtualbox, command-line on the left, GUI on the right.

Code I used in the example:

vcsrepo { 'C:\foo':
  ensure   => present,
  provider => git,
  source   => 'https://github.com/puppetlabs/puppetlabs-vcsrepo',
}

To keep the repository at the latest revision, set ensure to 'latest'. However, this overwrites any local changes to the repository.

vcsrepo { 'C:\foo':
  ensure   => present,
  provider => git,
  source   => 'https://github.com/puppetlabs/puppetlabs-vcsrepo',
}

To control what ref, tag, or branch the git repo is on, use the ref parameter:

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

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

vcsrepo { 'C:\foo':
  ensure   => present,
  provider => git,
  source   => 'git://example.com/repo.git',
  revision => '1.1.2rc1',
}
Peter Souter
  • 5,110
  • 1
  • 33
  • 62
  • Hey, what did you use to make that gif? – Chris Pitman Jun 07 '15 at 05:04
  • thanks Peter but I'm on Windows : Latest version is compatible with: Puppet Enterprise 3.x Puppet 3.x RedHat, Ubuntu, Debian, SLES, Scientific, CentOS, OracleLinux – BaltoStar Jun 08 '15 at 17:40
  • Yep, the machine on the left in the screenshot is a Windows 2012R2 server with Puppet installed on it. The version compatibility in the metadata is those platforms that are explicitly supported, it might work on other platforms also (which it does in the case of Windows! :D) – Peter Souter Jun 09 '15 at 08:54
  • Peter to what degree does puppetlabs-vcsrepo ensure the repo ? is it ensuring the repo is always in a usable state ? does it re-clone if entire repo ( or even repo git config files ) are deleted ? is it checking for changes on a schedule which it then pulls-down ? – BaltoStar Jun 11 '15 at 11:42
  • You can see the examples in https://github.com/puppetlabs/puppetlabs-vcsrepo#usage, but the simple answer is ensure just does a git clone, then wont touch it unless you delete the directory. Latest will always ensure that it's the latest version. The revision parameter lets you point at a specific branch or ref. – Peter Souter Jun 11 '15 at 12:15
  • Peter my app will create/checkout a working branch, add/modify a file, stage/commit/push. Will puppetlabs-vcsrepo notice that that current branch is not master and switch it back ? I don't want that to happen. – BaltoStar Jun 23 '15 at 18:38
  • If you choose "ensure=>present" it will only check that the repo exists and has the right endpoint, changes made by your app wont be reverted. – Peter Souter Jun 23 '15 at 19:00
  • thanks Peter, could you please verify this is correct line to add to Puppetfile : `mod 'puppetlabs/puppetlabs-vcsrepo', '1.3.0'` ? – BaltoStar Jun 23 '15 at 19:27
  • Yep, that's the latest release, and the release I tested on the Windows machine – Peter Souter Jun 23 '15 at 20:14
  • do you have a solution for securely storing credentials on puppet-server and including in vcsrepo config ? – BaltoStar Jun 23 '15 at 22:13