PROBLEM : Cannot require an Exec

4,184 views
Skip to first unread message

am-aaron

unread,
Oct 2, 2012, 4:36:10 PM10/2/12
to puppet...@googlegroups.com
hello:

i currently am using Puppet to run some commands in a sequence. there are two sequences of exec resources. we found that we cannot use require => Exec and it does not work at all as expected. here is some sample code.

exec { "exec-AAA":
  command => "/bin/true",
  returns => 0,
  notify  => Exec["exec-BBB"],
}
exec { "exec-BBB":
  refreshonly => true,
  command     => "/bin/false",
  returns     => 0,
  notify      => Exec["exec-CCC"],
}
exec { "exec-CCC":
  refreshonly => true,
  command     => "/bin/touch /tmp/CCC",
  returns     => 0,
}

exec { "exec-DDD":
  require => Exec["exec-CCC"],
  command => "/bin/true",
  returns => 0,
  notify  => Exec["exec-EEE"],
}
exec { "exec-EEE":
  refreshonly => true,
  command     => "/bin/false",
  notify      => Exec["exec-FFF"],
}
exec { "exec-FFF":
  refreshonly => true,
  command     => "/bin/touch /tmp/FFF",
  returns     => 0,
}

ms1:/root/aaron> puppet apply t1.pp

notice: /Stage[main]//Exec[exec-AAA]/returns: executed successfully
err: /Stage[main]//Exec[exec-BBB]: Failed to call refresh: /bin/false returned 1 instead of one of [0] at /root/aaron/t1.pp:11
notice: /Stage[main]//Exec[exec-DDD]/returns: executed successfully
err: /Stage[main]//Exec[exec-EEE]: Failed to call refresh: /bin/false returned 1 instead of one of [0] at /root/aaron/t1.pp:28
notice: Finished catalog run in 0.36 seconds

in the example above, how did Exec["exec-DDD"] run when Exec["exec-CCC"] did not run and Exec["exec-DDD"] require Exec["exec-CCC"]?

ms1:/root/aaron> puppet apply --debug t1.pp

info: Applying configuration version '1349209769'
debug: /Stage[main]//Exec[exec-DDD]/require: requires Exec[exec-CCC]
debug: /Stage[main]//Exec[exec-DDD]/notify: subscribes to Exec[exec-EEE]
debug: /Stage[main]//Exec[exec-BBB]/notify: subscribes to Exec[exec-CCC]
debug: /Stage[main]//Exec[exec-AAA]/notify: subscribes to Exec[exec-BBB]
debug: /Stage[main]//Exec[exec-EEE]/notify: subscribes to Exec[exec-FFF]
debug: /Schedule[never]: Skipping device resources because running on a host
debug: /Schedule[daily]: Skipping device resources because running on a host
debug: /Schedule[monthly]: Skipping device resources because running on a host
debug: /Schedule[puppet]: Skipping device resources because running on a host
debug: /Schedule[hourly]: Skipping device resources because running on a host
debug: /Schedule[weekly]: Skipping device resources because running on a host
debug: Exec[exec-AAA](provider=posix): Executing '/bin/true'
debug: Executing '/bin/true'
notice: /Stage[main]//Exec[exec-AAA]/returns: executed successfully
debug: /Stage[main]//Exec[exec-AAA]: The container Class[Main] will propagate my refresh event
info: /Stage[main]//Exec[exec-AAA]: Scheduling refresh of Exec[exec-BBB]
debug: Exec[exec-BBB](provider=posix): Executing '/bin/false'
debug: Executing '/bin/false'
err: /Stage[main]//Exec[exec-BBB]: Failed to call refresh: /bin/false returned 1 instead of one of [0] at /root/aaron/t1.pp:11
debug: Exec[exec-DDD](provider=posix): Executing '/bin/true'
debug: Executing '/bin/true'
notice: /Stage[main]//Exec[exec-DDD]/returns: executed successfully
debug: /Stage[main]//Exec[exec-DDD]: The container Class[Main] will propagate my refresh event
info: /Stage[main]//Exec[exec-DDD]: Scheduling refresh of Exec[exec-EEE]
debug: Exec[exec-EEE](provider=posix): Executing '/bin/false'
debug: Executing '/bin/false'
err: /Stage[main]//Exec[exec-EEE]: Failed to call refresh: /bin/false returned 1 instead of one of [0] at /root/aaron/t1.pp:28
debug: Class[Main]: The container Stage[main] will propagate my refresh event
debug: Finishing transaction 70054935787440
debug: Storing state
debug: Stored state in 0.06 seconds
notice: Finished catalog run in 0.37 seconds
debug: /File[/var/lib/puppet/rrd]/seluser: Found seluser default 'system_u' for /var/lib/puppet/rrd
debug: /File[/var/lib/puppet/rrd]/selrole: Found selrole default 'object_r' for /var/lib/puppet/rrd
debug: /File[/var/lib/puppet/rrd]/seltype: Found seltype default 'puppet_var_lib_t' for /var/lib/puppet/rrd
debug: /File[/var/lib/puppet/rrd]/selrange: Found selrange default 's0' for /var/lib/puppet/rrd
debug: Finishing transaction 70054934905120
debug: Recieved report to process from ms1
debug: Processing report from ms1 with processor Puppet::Reports::Store

as you can see in the debug run, even though Exec["exec-DDD"] require Exec["exec-CCC"], and the latter does not run, the former runs. what is going on here?

thank you for your time.

have a nice day,

Aaron
--
{<-encapsulation->}


This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.

Miguel Di Ciurcio Filho

unread,
Oct 2, 2012, 8:32:46 PM10/2/12
to puppet...@googlegroups.com
On Tue, Oct 2, 2012 at 5:36 PM, am-aaron <aaron....@ammeon.com> wrote:
>
> exec { "exec-AAA":
> command => "/bin/true",
> returns => 0,
> notify => Exec["exec-BBB"],
> }
> exec { "exec-BBB":
> refreshonly => true,
> command => "/bin/false",
> returns => 0,
> notify => Exec["exec-CCC"],
> }
> exec { "exec-CCC":
> refreshonly => true,
> command => "/bin/touch /tmp/CCC",
> returns => 0,
> }
>
> exec { "exec-DDD":
> require => Exec["exec-CCC"],
> command => "/bin/true",
> returns => 0,
> notify => Exec["exec-EEE"],
> }

I tested your code and indeed, it is a strange behavior.

I guess the root cause of the problem is the `refreshonly => true` of exec-CCC.

My reading of the situation:
- exec-BBB runs and fails, sending nothing to exec-CCC.
- exec-CCC has `refreshonly => true`, since exec-BBB has failed, it
does nothing.
- exec-DDD runs, even having `require => Exec['exec-CCC']` which has
not received a notify because exec-BBB failed.

I did a test using the chaining syntax and the behavior is the same:

Exec['exec-AAA'] ~> Exec['exec-BBB'] ~> Exec['exec-CCC'] -> Exec['exec-DDD']

# puppet apply test.pp
/Stage[main]//Exec[exec-AAA]/returns: executed successfully
Error: /Stage[main]//Exec[exec-BBB]: Failed to call refresh:
/bin/false returned 1 instead of one of [0]
Error: /Stage[main]//Exec[exec-BBB]: /bin/false returned 1 instead of one of [0]
/Stage[main]//Exec[exec-DDD]/returns: executed successfully

Exec['exec-CCC'] does not receive a notification and does not run
because exec-BBB failed. Although, it fulfills the `require`
relationship with Exec['exec-DDD'], which runs.

Note: changing the relationship of Exec['exec-CCC'] and
Exec['exec-DDD'] from `require` para `notify` does not solve the
problem, the behavior is the same.

Very odd. The documentation about `exec` does not say anything about
this behavior of `refreshonly` [1].

[1] http://docs.puppetlabs.com/references/stable/type.html#exec

Guzman Braso

unread,
Oct 2, 2012, 10:14:53 PM10/2/12
to puppet...@googlegroups.com
I think it's the expected behavior... 

My reading is that if you want Exec["exec-DDD"] being run only when Exec["exec-CCC"] have run, and at the same time, Exec["exec-CCC"] has refreshonly attribute, then it's not require the way, it's set it to refreshonly and tell Exec["exec-CCC"] to notify Exec["exec-DDDD"].

When you require exec-CCC from exec-DDD, puppet will make sure of place exec-CCC before exec-DDD, but if exec-CCC does not run, be it for a ifonly non true, be it for been a refreshonly type without notice, it will continue anyway.

>
> This is used purely for guaranteeing that changes to required objects happen before the dependent object"
>

The word "happen" here is tricky, I would say then than happen means "are parsed and run if needed". 

Or... I'm more lost than I thought with puppet and my english still sucks :)

Cheers

Guzman


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.




--
GuruHub - Guzmán Brasó
http://www.guruhub.com.uy - +59898674020
Rivera 3565 - CP11400 - Montevideo, Uruguay

jcbollinger

unread,
Oct 3, 2012, 10:07:18 AM10/3/12
to puppet...@googlegroups.com


The 'require' metaparameter is no different for Exec resources than for any other resource type: foo { 'myfoo': require => Bar['mybar'] } means that when the agent applies the catalog, it must successfully apply resource Bar['mybar'] before it applies resource Foo['myfoo'].  Your issue is basically about what it means to "apply" an Exec.

In simple cases, "applying" an Exec involves running its command, and the success or failure of the resource is based on the command's exit status.

When you set "refreshonly => true" on an Exec resource, that does not make application of the resource conditional.  Puppet will always (attempt to) apply every resource in the catalog it receives.  Instead, "refreshonly => true" makes the steps taken to apply the Exec conditional.  If such an Exec has not been signaled then applying it is a no-op that automatically succeeds.  That's why you are seeing a resource that 'require's Exec['exec-CCC'] being applied even though CCC's command is never run.

Note also that Exec has other parameters that can lead to instances being applied successfully without their commands being run.  The 'creates', 'onlyif', and 'unless' parameters all provide mechanisms for Puppet to decide that an Exec resource is already in sync without running its (main) command.  Applying a resource of any type that is already in sync is also a no-op that automatically succeeds.

Presumably, the question arises from attempts to develop manifests for a particular configuration objective.  If you give us some details about the job you're trying to perform, then we may be able to give you better-targeted advice.


John

Reply all
Reply to author
Forward
0 new messages