Ask Your Question
0

Exec ordering

asked 2017-11-03 17:20:28 -0600

hem gravatar image

My need is this...

1. look for changes to /tmp/file-1 file
    a. if there is a change, execute in the following order
        i.   run cmd-3
        ii.  run cmd-2
        iii. run cmd-1
    b. If there is NO change to /tmp/file-1 file, do not run anything

My code is like this...

exec { 'exec-3':
  command => "sudo cmd-3",
  path    => '/usr/local/bin',
  require => File["/tmp/file-1"],
}

exec { 'exec-2':
  command => "sudo cmd-2",
  path    => '/usr/local/bin',
  require => Exec['exec-3'],
}

exec { 'exec-1':
  command     => "sudo cmd-1",
  path        => '/usr/local/bin',
  require     => Exec['exec-2'],
  subscribe   => File["/tmp/file-1"],
  refreshonly => true,
}

But, whether there is a change to /tmp/file-1 or not, cmd-3 and cmd-2 always run. How do I prevent it? I do not want "require" to be run in exec-1 when there is no change to /tmp/file-1.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2017-11-04 15:09:45 -0600

Puppet is a declarative language. You do not program a script or something. In your case, I'd recommend writing a separate shell script and execute that.

Historically you could've used the audit metaparameter:

file { 'my_file':
    path                          => '/tmp/file-1',
    ensure                        => present,
    audit                         => ['content'],
}

Exec {
    path                          => '/usr/local/bin/',
    refreshonly                   => true,
}

exec { 'exec_2':
    command                       => 'cmd-2',
}

exec { 'exec_1':
    command                       => 'cmd-1',
}

exec { 'exec_0':
    command                       => 'cmd-0',
}

File['my_file'] ~> Exec['exec_2'] ~> Exec['exec_1'] ~> Exec['exec_0']

Also resource defaults like that above aren't recommended anymore (see § area of effect).

PS: Any specific reason not use the user attribute for the exec resources?

edit flag offensive delete link more

Comments

It worked. Thank you.

hem gravatar imagehem ( 2017-11-06 16:24:11 -0600 )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

1 follower

Stats

Asked: 2017-11-03 17:19:54 -0600

Seen: 292 times

Last updated: Nov 04