7

I have a CentOS base box in Vagrant that I'm standing up with a puppet manifest. Here's what's in the manifest so far:

class base {
    exec { "sudocmd":
        path => ["/usr/bin/","/usr/sbin/","/bin"],
        command => "sudo yum update -y",
    }

    package { "man":
        ensure => present,
    }

    package { "bind":
        ensure => present,
    }

    package { "bind-utils":
        ensure => present,
    }
}

include base

But when I say vagrant up, I get an error that sudocmd yum update exited with a 1. I've looked on the web, but I haven't found a solution for this yet. Any help?

========EDIT========= I read the answers and I agree - thanks guys. I'm just using this on a dev box to mess around and I needed it to be up to date before I started doing work on it.

George K.
  • 2,867
  • 4
  • 19
  • 28

3 Answers3

11

With puppet, you shouldn't need to use sudo, just run the yum command directly. Normally commands will run as root by default, but you can specify what user.

exec { "sudocmd":
    path => ["/usr/bin/","/usr/sbin/","/bin"],
    command => "yum update -y",
    user => root,
}

However, I strongly recommend that you do not use any kind of non-conditional exec with puppet. That will run every time puppet runs. As Forrest already said, it's not what puppet is designed for. I wouldn't use puppet for a yum update, and my execs always have creates, onlyif, refreshonly or unless to ensure they only run when needed.

Community
  • 1
  • 1
freiheit
  • 4,976
  • 37
  • 35
3

So Puppet isn't really meant to perform tasks like a yum update. It's a configuration management tool, not something that completely replaces this sort of task. In addition you run into a lot of issues with this. What if Puppet is daemonized? Will this negatively impact our production environment? What happens if a user accidentally runs Puppet and it updates a package that breaks our scripts (JDK, MySQL, PHP, etc.). As far as I'm aware there is no solution to this because it's not really considered a problem. Scott Pack over on Serverfault provided a very descriptive answer to a similar question.

Community
  • 1
  • 1
Forrest
  • 1,370
  • 9
  • 20
0

updating "path" attribute helps me. sudo and apt-get commands are available in /usr/bin/ path

exec { 'autoclean':
        command   => 'apt-get autoclean',
        path      => '/usr/local/bin/:/bin/:/usr/bin/',
        cwd       => '/home',
} 

my puppet version: 5.5.1

Raj
  • 1,100
  • 3
  • 20
  • 33