Ask Your Question
0

Exec with creates: how many times does it check?

asked 2018-05-07 18:11:18 -0500

hem gravatar image

I've the below exec blocks...

   exec { 'run the script':
      command     => "python my-script.py",
      path        => '/bin:/usr/bin:/usr/local/bin',
      timeout     => 900,
      subscribe   => File["my-settings.yaml"],
      refreshonly => true,
    }

    exec { 'check if file exists':
      command => 'true',
      path    => '/bin:/usr/bin:/usr/local/bin',
      creates => '/var/lib/my-file',
      notify  => Exec['run the script']
    }

I'd like the exec block run the script to run whenever there is a change to my-settings.yaml OR whenever the file /var/lib/my-file is not present. The file is created by python my-script.py from the command in exec block run the script.

I'm just wondering how many times the exec block check if file exists would run if python my-script.py fails to create /var/lib/my-file. Will it run forever or does it run with a preset interval?

I also wonder if I need refreshonly in the exec block check if file exists. My little Puppet knowledge says no, though.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2018-05-09 05:57:16 -0500

exec resources that are refreshonly => true are “scheduled”. That means, they are defined during catalog compilation, but are only triggered to run if there is a notifying event for them.

Multiple notifications accumulate to one actual invocation of the command. Usually. There is the theoretical chance a command is run multiple times throughout a single puppet run, hence the idempotence requirement for commands.

Now that means your script is run at least once, if one of your resources triggers it, and at most the total number of notifying resources. Your script will be killed if timeout seconds has been reached. The (abstract notion of) resource is then considered as failed and the command won't be invoked again (even if another event occurs [I guess]).

If your script returns a non-zero return value (cf. returns attribute) the tries attribute will limit the maximum number of attempts (per each notification) until the resource is considered as failed.

I'd like the exec block run the script to run whenever there is a change to my-settings.yaml OR whenever the file /var/lib/my-file is not present.

I assume this is an inclusive or. I guess there's no chance to express a Xor-relation with Puppet's onboard resources at all.

I also wonder if I need refreshonly in the exec block check if file exists. My little Puppet knowledge says no, though.

Once you define an exec as refreshonly it won't be run, and therefore can not notify other resources, unless it itself receives a notification event. You do not want that.

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: 2018-05-07 18:11:18 -0500

Seen: 29 times

Last updated: May 09