Ask Your Question

what is the proper code to exec commands using puppet module?

asked 2017-02-03 13:28:36 -0500

Any command I tried to execute using puppet module don't work. My puppet code:

class soh-ssl { exec { "httpdstop": command => "/etc/init.d/httpd stop", path => "/bin/:/sbin/:/usr/bin:/usr/sbin/",

exec { 'make_dir':

command => 'mkdir -p /home/xfarilc.admin/dirz',

path => '/bin/:/sbin/:/usr/bin/:/usr/sbin/',

exec { 'ssldisable':

command => "/bin/sed -i 's/testaa/testx/g' /home/xfarilc.admin/testa",

path => '/bin',

} }

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-02-04 22:16:48 -0500

reesek gravatar image

updated 2017-02-04 22:17:25 -0500

The example code you've provided for each exec resource type is not intended to be used in that fashion. You should be using a combination of the native service and file types to manage the httpd service and directory creation, and something like file_line resource type provided in puppetlabs/stdlib to handle the ssldisable.

service { 'httpd':
  ensure => 'stopped',

file { '/usr/local/mydir':
  ensure => 'directory',
  owner  => '0',
  group  => '0',
  mode   => '0755',

(OR, if any of the parent directories do not exist, you might have to do it as follows. There are other ways to achieve 'mkdir -p' behavior without having to specify each leg of the directory tree inside an array -> look for dir_tree in the puppet forge for example)

file { [  '/usr/local/mydir', '/usr/local/mydir/subdir', '/usr/local/mydir/subdir/bin', '/usr/local/mydir/subdir/log' ]:
  ensure => 'directory',
  owner  => 'root',
  group  => 'root',
  mode   => '0755',

file_line { 'ssldisable':
  ensure => present,
  path   => '/home/xfarilc.admin/testa',
  line   => 'testx',
  match  => '^testaa',

Not knowing the content of the test file, your match will likely be different that what I've demonstrated above, but it makes the point.

Please accept or upvote if this answers your question. Thanks!

edit flag offensive delete link more


I used this code to replace testaa in /home/xfarilc.admin/testa file with testx, but it didn't work: class soh-ssl { file_line { 'ssldisable': ensure => present, path => '/home/xfarilc.admin/testa', line => 'testx', match => '^testaa', } } testa file content: testbb testaa

farinaslorenzo gravatar imagefarinaslorenzo ( 2017-02-06 14:54:18 -0500 )edit

It all depends on the content of your file. match is looking for a string 'testaa' at the beginning of the line. Check out file_line doc: I also noticed a dash in the class name. Hyphens are not allowed in class names. I would refrain from doing that.

reesek gravatar imagereesek ( 2017-02-08 11:01:26 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2017-02-03 13:28:36 -0500

Seen: 22 times

Last updated: Feb 04