> Example class that brings on this behaviour: > > Class ldap::setup { > $loc = getLocation() #Custom function that returns a location > based on IP address fact > > case $loc { > london: { > $bind = "cn=base,dc=site,dc=com" > notice ("Target 1 - bind - ${bind}") > } > ... > default: { > $bind = "cn=def,dc=site,dc=com" > notice ("Target 1 - bind - ${bind}") > } > } > > notice ("Target 2 - bind - ${bind}") > $ldapParams = callCustomFunction($bind) > > exec { authconfig: > command => "authconfig ${ldapParams}" > path => ["/usr/sbin"] > } > } > > So when this class is used, Target 2 fires before Target 1 is called. > As a result, the call to callCustomFunction has an empty parameter > list as $bind has not been set yet. The solution is to add the > callCustomFunction call to every arm of the case. When you have 20 > plus conditionals, this is not elegant. > > Any ideas? > > Geoff Newell------------------------------------------------------------------------ For important statutory and regulatory disclosures and more information about Barclays Capital, please visit our web site at http://www.barcap.com. Internet communications are not secure and therefore the Barclays Group does not accept legal responsibility for the contents of this message. Although the Barclays Group operates anti-virus programmes, it does not accept responsibility for any damage whatsoever that is caused by viruses being passed. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Barclays Group. Replies to this email may be monitored by the Barclays Group for operational or business reasons. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. ------------------------------------------------------------------------
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday 19 November 2007, Geoff.Newell@barclayscapital.com wrote:> > Example class that brings on this behaviour: > > > > Class ldap::setup { > > $loc = getLocation() #Custom function that returns a location > > based on IP address fact > > > > case $loc { > > london: { > > $bind = "cn=base,dc=site,dc=com" > > notice ("Target 1 - bind - ${bind}") > > } > > ... > > default: { > > $bind = "cn=def,dc=site,dc=com" > > notice ("Target 1 - bind - ${bind}") > > } > > } > > > > notice ("Target 2 - bind - ${bind}") > > $ldapParams = callCustomFunction($bind) > > > > exec { authconfig: > > command => "authconfig ${ldapParams}" > > path => ["/usr/sbin"] > > } > > } > > > > So when this class is used, Target 2 fires before Target 1 is called. > > As a result, the call to callCustomFunction has an empty parameter > > list as $bind has not been set yet. The solution is to add the > > callCustomFunction call to every arm of the case. When you have 20 > > plus conditionals, this is not elegant.variable assignment within a scope is still order dependent. Please set all variables in the beginning of the class to avoid such problems. Regards, David - -- The primary freedom of open source is not the freedom from cost, but the free- dom to shape software to do what you want. This freedom is /never/ exercised without cost, but is available /at all/ only by accepting the very different costs associated with open source, costs not in money, but in time and effort. - -- http://www.schierer.org/~luke/log/20070710-1129/on-forks-and-forking -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHQVEz/Pp1N6Uzh0URAvSAAKCP2EaZ2TrRl0cTeMej+uVL2jDNcgCfaG4S cXQpOr/K64QGTR9kcv/N3d8=hbfM -----END PGP SIGNATURE-----