With a puppet, you do not need to use sudo , just run the yum command. Typically, commands run as root by default, but you can specify which user.
exec { "sudocmd": path => ["/usr/bin/","/usr/sbin/","/bin"], command => "yum update -y", user => root, }
However, I strongly recommend that you not use any conditional exec with a puppet. This will be done every time the puppets are working. As Forrest said , this is not what the puppet is for. I would not use a puppet for yum update , and my exec always had creates , onlyif , refreshonly or unless , to make sure that they only run if necessary.
source share