I'm not sure how much membership-specific code you have, but if it's
more than just this you may want a custom fact rather than using
unless/onlyif every time.  We use QAS instead of Samba for domain
membership but the idea is the same:


--vas_status.rb--
require 'facter'

vastool = '/opt/quest/bin/vastool'

if File.exists? vastool

  `#{vastool} status`

  if $?.success?
    Facter.add("vas_status") do
      setcode { "joined" }
    end
  else
    Facter.add("vas_status") do
      setcode { "unjoined" }
    end
  end
else
  Facter.add("vas_status") do
    setcode { "uninstalled" }
  end
end


On 03/05/2012 12:35 PM, Kinzel, David wrote:
>> exec {
>>     path => "/usr/bin",
>>     onlyif => 'test `net ads testjoin 2>&1 | grep Join | sed -e \'s/
>> *Join is OK*/1/g\' -ne 1'
>>     command => 'net ads join -U <administrator>%<password>
>> createcomputer="Samba"
>> }
>>
>> The onlyif doesn't work if the result of the testjoin returns "Join is
>> OK", depending on the test syntax, it just runs or doesnt regardless.
>> There has to be a better way to do this... anyone with experience
> 
> That regex doesn't look very nice. Are you sure running it from a regular 
> shell produces what you want? What exactly is the net ads testjoin output 
> look like?
> 
> It would be much simpler to use:
> 
> onlyif => "net ads testjoin 2>&1 | grep 'Join is OK'"
> 
> Which will use the return code of grep.
> 
> If your code is exactly as shown in this email you are also missing a ` in 
> your only if test, and your command => is not closed either.
> 
>> setting this up that cares to share?  Anyone try using the
>> "refreshonly" option somehow?  Again, my goal here is just for the net
>> ads join to run when the server is NOT joined to the domain (which
>> should be rarely).  Thanks
>>
>> -- 
>> You received this message because you are subscribed to the 
>> Google Groups "Puppet Users" group.
>> To post to this group, send email to puppet-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> puppet-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/puppet-users?hl=en.
>>
>>
> 
> 
> This email communication and any files transmitted with it may contain
> confidential and or proprietary information and is provided for the use of the
> intended recipient only. Any review, retransmission or dissemination of this
> information by anyone other than the intended recipient is prohibited. If you
> receive this email in error, please contact the sender and delete this
> communication and any copies immediately. Thank you.
> 
> http://www.encana.com
> 

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

Reply via email to