Ask Your Question
0

When does a refresh-only trigger?

asked 2016-12-13 22:54:03 -0500

Joseph Carlos gravatar image

Is there any guarantee on when an exec will run if it subscribes to another resource and has refreshonly set to true? For example, in the following code the exec will run on a change to the file resource. But will it necessarily run before the package resource? I can find nothing in the Puppet documentation that answers this question.

file { '/etc/apt/preferences.d/debootstrap':
  source => "/tmp/debootstrap"
}

exec { 'aptitude update':
  command     => 'aptitude update',
  path        => '/bin:/usr/bin',
  subscribe   => File['/etc/apt/preferences.d/debootstrap'],
  refreshonly => true,
}

package { 'debootstrap':
  ensure  => installed,
  require => File['/etc/apt/preferences.d/debootstrap'],
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-12-14 08:07:38 -0500

DarylW gravatar image

If you want it to run before the package resources, make it so

file { '/etc/apt/preferences.d/debootstrap':
  source => "/tmp/debootstrap"
}

exec { 'aptitude update':
  command     => 'aptitude update',
  path        => '/bin:/usr/bin',
  subscribe   => File['/etc/apt/preferences.d/debootstrap'],
  refreshonly => true,
  before => Package['debootstrap'],
}

package { 'debootstrap':
  ensure  => installed,
  require => File['/etc/apt/preferences.d/debootstrap'],
}

Or you could require the exec via the package resource

file { '/etc/apt/preferences.d/debootstrap':
  source => "/tmp/debootstrap"
}

exec { 'aptitude update':
  command     => 'aptitude update',
  path        => '/bin:/usr/bin',
  subscribe   => File['/etc/apt/preferences.d/debootstrap'],
  refreshonly => true,
}

package { 'debootstrap':
  ensure  => installed,
  require => [File['/etc/apt/preferences.d/debootstrap'],Exec['aptitude update']],
}

The exec resource is still placed in the resource ordering even if it doesn't run... the refreshonly portion is the thing that determines if it should run or not.

If you are doing this sort of thing in multiple places, you may want to use the spaceship/collection operator. Exec['aptitude update'] -> Package<| |> Do note, however, that using the collection operator without a match can easily lead to dependency cycles, but the match can only work on things you've specified in your catalog, for instance if you were trying to match on provider=debian but it was just 'inferred' by puppet, you wouldn't get the package resources you expected unless you explicitly defined it.

edit flag offensive delete link more

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: 2016-12-13 22:54:03 -0500

Seen: 94 times

Last updated: Dec 14 '16