Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppet manifest - 'sudo' commands?

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.

like image 707
George K. Avatar asked Dec 30 '12 05:12

George K.


2 Answers

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.

like image 176
freiheit Avatar answered Nov 02 '22 23:11

freiheit


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.

like image 25
Forrest Avatar answered Nov 03 '22 00:11

Forrest