0
votes

A chocolatey provider is required, to install packages this will work but only works once another pp file finishes executing.

The problem is that puppet evaluates both files under the node statement and errors on invalid provider; the problem is I run the first pp file by commenting the other out , then let it run & uncomment it then rerun with puppet agent --test it all works.

I have tried tags and used an if statement with the tag , but this doesn't seem to work either.

class windows::chocolatey {
  exec { 'set_executionpolicy':
    command  => "set-executionpolicy unrestricted -force -scope process;
(iex((new-object
net.webclient).DownloadString('https://chocolatey.org/install.ps1')))>\$null
2>&1",
    provider => 'powershell',
    creates  => 'C:/ProgramData/chocolatey',
  }

node "web-iis-02" {
  class { 'windows':} #chocolatey installing to allow atom.pp to work
  class { 'atom': } # init.pp below install using chocolatey

#installs package
class atom {
  if tagged(windows) {
    include atom::pakages
    notify { "Calling Pakagepp script": }
  }
}

#if tagged init.pp above calls this:
class atom::pakages {
  include chocolatey
  package { 'Atom':
    ensure => 'latest',
    provider => 'chocolatey',
  }

I get this from pakages.pp:

Error: Failed to apply catalog: Parameter provider failed on Package[Atom]: Invalid package provider 'chocolatey' (file: /etc/puppetlabs/code/environments/production/modules/atom/manifests/pakages.pp, line: 3)

1
I need the node statement to execute both windows class & atom class without atom complaining about the choco provider not being there, the atom class uses chocolatey to install - philip cripps

1 Answers

0
votes

Try adding a require dependency, so the atom class is declared after the windows class:

class { 'windows': }
class { 'atom':
  require => Class['windows'],
}

or quick and dirty:

class { 'windows': }
-> class { 'atom': }

You'll need to remove that tagged condition as it isn't needed.

I can't quite tell from your question which classes depend on which, but I'm pretty sure it is require you need. You may need to add a require for the chocolatey class:

class { 'atom':
  require => Class['windows', 'chocolatey'],
}