2

I am experimenting with Puppet using Vagrant. I'm new to Puppet.

I'm installing modules in my Puppet manifest using the approach suggested at: Can I install puppet modules through puppet manifest?

My default.pp contains something like:

$dsesterojava = 'dsestero-java'
exec { 'dsestero-java':
   command => "puppet module install ${dsesterojava}",
   unless  => "puppet module list | grep ${dsesterojava}",
   path    => ['/usr/bin', '/bin']
}

include java::java_7 

I'm trying to import a module and then immediately use the classes defined in it.

Currently, I get:

Error: Could not find class java::java_7

If I comment out the include line and re-run it. The module installs. If I then removed the comment and run the provisioning again then it works.

There is some kind of "chicken and egg" situation here. Can I use a module in the same Puppet manifest that installs it?

How should I solve it?

Mark McLaren
  • 11,470
  • 2
  • 48
  • 79
  • 1
    No, you cannot do this. When your catalog is compiled, Puppet will search for all of the required code and data. Since the `java` module does not exist until catalog application, the compilation of a catalog depending upon it will fail. You are absolutely dealing with a "chicken and egg" situation here. I highly recommend against using Puppet code to install Puppet code. – Matthew Schuchard Nov 22 '17 at 12:57
  • 1
    Additionally, the link you provided does not suggest this approach, but rather to use librarian-puppet. That (or its successors r10k and code-manager) are highly recommended over this approach. – Matthew Schuchard Nov 22 '17 at 12:59
  • Thanks @MattSchuchard. I'm just learning Puppet but we have Puppet Enterprise locally, which I have just discovered uses r10k - so I shall give that a go. – Mark McLaren Nov 22 '17 at 13:50
  • Installing Puppet modules for use within Vagrant is also kind of a different beast entirely when you are using them with the internal Puppet provisioner for Vagrant. I expect sooner or later Frederic Henri will arrive and explain the best way to do this, as whenever I Puppet+Vagrant I am doing it for testing purposes and therefore never have to deal with this. Also, if you have Puppet Enterprise you can use "r10k++" (Code Manager), but this would be for the agent provisioner and not the apply provisioner. – Matthew Schuchard Nov 22 '17 at 13:52
  • You really should mark @MattSchuchard's first answer as correct, as this code would never work. I think the poster may be looking for a masterless Puppet set-up, which is why he was looking into librarian-puppet. – Luke Dec 11 '17 at 21:57
  • I don't think you can mark a comment as an answer - I would if I could – Mark McLaren Dec 11 '17 at 23:26
  • 1
    Well then, upon request I have converted and expanded the comments into an answer. – Matthew Schuchard Dec 12 '17 at 15:40

1 Answers1

3

No, you cannot do this. When your catalog is compiled, Puppet will search in the appropriate directories for all of the required code and data. Since the java module does not exist until catalog application, the compilation of a catalog (occurs prior to application) depending upon it will fail. You are absolutely dealing with a "chicken and egg" situation here. I highly recommend against using Puppet code to install Puppet code.

Alternatively, the recommended approach to install and manage your Puppet modules is to use one of these solutions:

These will also solve the problem for you within the Vagrant if you are using the agent provisioner and subscribing the Vagrant instance to a Puppet Master.

If you are using the apply provisioner inside of Vagrant, then you will need to go a different route. The simplest solution is to use the shell provisioner to install Puppet modules via module install after the Puppet installation (unless you are using a Vagrant box with Puppet baked in, in which case you are probably not installing Puppet on it). Alternatively, you could share a directory with the host where your modules are installed, or install the librarian-puppet or r10k gems onto the Vagrant box and then use them to install into the appropriate path. I can go into more detail on these upon request.

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
  • 1
    Worth mentioning here https://github.com/xorpaul/g10k, a lightning fast r10k replacement in Go. I made the switch and won't look back. – Alex Harvey Dec 13 '17 at 12:49
  • @AlexHarvey as much as I loathe developing in go, I have already seen the performance comp between Goss and Serverspec so I can guess something similar is happening here. I need to find out if Puppet knows about this and wants to internalize it, or at least make this a swappable backend for r10k with Code Manager; either would allow me to pitch it to Enterprise organizations. Anyway, great find there. – Matthew Schuchard Dec 13 '17 at 13:26
  • Well I told them about it on the Puppet Community Slack and a few people seemed impressed. They ought to internalize it. – Alex Harvey Dec 13 '17 at 14:34