Re: SOLVED Re: [Puppet Users] Two Facter files seem to conflict

2016-10-22 Thread Rob Nelson
Awesome, glad to hear that helped!

On Saturday, October 22, 2016,  wrote:

> Thank you Rob.  I have it working using slice and some new variables.
>
> Here are my final scripts.
>
> Facter.add(:server_role) do
>   setcode do
> ip_address = Facter.value(:ipaddress).tr('.', '')
> ip_address = ip_address.to_i
> host = Facter.value(:hostname)
> if host[0,1] != "a"
>   server_role = 'workstation'
> else
>   if ip_address.between?(1921680160, 1921680170)
> server_role = host.slice(0,2)
>   else
> server_role = host.slice(0.4)
>   end
> end
>   end
> end
>
> Facter.add(:location_code) do
>   setcode do
> address = Facter.value(:ipaddress).tr('.', '')
> address = address.to_i
> host = Facter.value(:hostname)
> if host[0,1] != "a"
>   net = Facter.value(:network)
>   net = net[0..-3] += '.30'
>   net = Facter::Core::Execution.exec("nslookup #{net} | grep name |
> awk '{print $4}'")
>   net = net.partition('.').first
>   net = net[0..3]
> else
>   if address.between?(1921680160, 1921680170)
> location_code = host.slice(0,2)
>   else
> location_code = host.slice(0,4)
>   end
> end
>   end
> end
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users+unsubscr...@googlegroups.com
> 
> .
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/puppet-users/e0a376db-83c9-4366-9ddd-318e6e298b36%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 

Rob Nelson
rnels...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAC76iT8jmP9Kzkz15DVwWs4F%3D278fxG5mVf-XXEOmWc2SNHzyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


SOLVED Re: [Puppet Users] Two Facter files seem to conflict

2016-10-22 Thread aarb000
Thank you Rob.  I have it working using slice and some new variables.

Here are my final scripts.  

Facter.add(:server_role) do
  setcode do
ip_address = Facter.value(:ipaddress).tr('.', '')
ip_address = ip_address.to_i
host = Facter.value(:hostname)
if host[0,1] != "a"
  server_role = 'workstation'
else
  if ip_address.between?(1921680160, 1921680170)
server_role = host.slice(0,2)
  else
server_role = host.slice(0.4)
  end
end
  end
end

Facter.add(:location_code) do
  setcode do
address = Facter.value(:ipaddress).tr('.', '')
address = address.to_i
host = Facter.value(:hostname)
if host[0,1] != "a"
  net = Facter.value(:network)
  net = net[0..-3] += '.30'
  net = Facter::Core::Execution.exec("nslookup #{net} | grep name | awk 
'{print $4}'")
  net = net.partition('.').first
  net = net[0..3]
else
  if address.between?(1921680160, 1921680170)
location_code = host.slice(0,2)
  else
location_code = host.slice(0,4)
  end
end
  end
end





-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/e0a376db-83c9-4366-9ddd-318e6e298b36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Two Facter files seem to conflict

2016-10-21 Thread Rob Nelson
I assume slice! modifies the string in place rather than returning the
resulting string without modifying the original, as most ! funcs do. Is
there a reason you are doing that rather than saving the result in another
variable and returning that value at the end?

I ask this because string assignment under the covers doesn't copy the
value, but creates a reference, so that modifying your new variable also
changes the original variable's contents. I am boarding a plane so cannot
confirm this, just a hunch. Regardless, I think you could get away with
using slice instead of slice! by assigning to a temp variable along the
way. It seems cleaner in general, and may as a bonus fix this, as well :)

On Friday, October 21, 2016,  wrote:

> Some additional information.
>
> I can confirm that the reason that
> server_role = Facter.value(:hostname)
> if server_role[0,1] != "a"
>
> isn't true for servers who's names do start with a is directly related to
> settings in the location_code.rb file
> if I rem out everything in server_role except
> server_role = Facter.value(:hostname)
> the hostname is printed with the first 2 or 4 characters removed as shown
> in location_code.erb
> if ip_address.between?(104127100, 104127255)
> location_code.slice!(0,2)
> else
> location_code.slice!(0,4)
> end
> If I change the numbers from 2 to 3, or 4 to 5 for example, the hostname
> is different on my remarked server_role.erb file
>
> I would assume that the line in server_role.erb
>
> server_role = Facter.value(:hostname)
>
> would get the proper hostname from Facter, but it doesn't appear to.
>
> Any ideas on why?
>
>
>
> On Friday, October 21, 2016 at 3:05:06 PM UTC-5, aar...@gmail.com
>  wrote:
>>
>> I have two custom facts and I have put each file in the directory for a
>> single module.  Both facts get loaded onto my clients.
>>
>> The problem I am having is that each fact runs successfully when it is by
>> itself, but when both run at the same time, the results aren't as expected.
>>
>> To test, I rename one fact as *.rb.bak, and then I get proper results.
>> Switch to the other fact, again, proper results.  Remove .bak so they both
>> run, results are wrong.
>>
>> Here are my .rb files.
>>
>> All of my servers start with the letter a and have either an aX or aXXX
>> which describes their physical location.  All of the servers end with 5
>> characters that describe the network they are on.  The remaining characters
>> describe what the server does.
>>
>> All of my workstations start with a #.
>>
>> What seems to happen, is that when both facts are running, none of my
>> servers start with "a" so all of my servers show up as workstations.
>>
>> It appears that 'location_code.slice! seems to run, so the prefix of my
>> hostname is gone and the first letter appears to be the part of the
>> hostname that describes the servers function.
>>
>> To test, I changed "a" in my code to "f" and my file server had the
>> proper server_role of file.
>>
>> I don't understand why this happens as my variables are different between
>> the two script
>>
>> I appreciate any assistance.
>>
>> require 'facter'
>>
>> Facter.add(:location_code) do
>>   setcode do
>> address = Facter.value(:ipaddress).tr('.', '')
>> address = address.to_i
>> location_code = Facter.value(:hostname)
>>   if address.between?(104127100, 104127255)
>> location_code.slice!(0,2)
>>   else
>> location_code.slice!(0,4)
>>   end
>>   end
>> end
>>
>>
>>
>>
>> require 'facter'
>>
>> Facter.add(:server_role) do
>>   setcode do
>> ip_address = Facter.value(:ipaddress).tr('.', '')
>> ip_address = ip_address.to_i
>> server_role = Facter.value(:hostname)
>> if server_role[0,1] != "a"
>>   server_role = 'workstation'
>> else
>>   if ip_address.between?(104127100, 104127255)
>> server_role.slice!(0,2)
>> else
>> server_role.slice!(0,4)
>> end
>> server_role = server_role[0..-6]
>> end
>>   end
>> end
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users+unsubscr...@googlegroups.com
> 
> .
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/puppet-users/3caf42f8-bd4a-4c38-aebc-d88ba0a6360b%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 

Rob Nelson
rnels...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 

Re: [Puppet Users] Two Facter files seem to conflict

2016-10-21 Thread warron.french
OK, sorry aarb.

--
Warron French


On Fri, Oct 21, 2016 at 4:44 PM,  wrote:

> Actually I meant that all of my workstations begin with a number.
>
> Thank you.
>
> On Friday, October 21, 2016 at 3:40:48 PM UTC-5, Warron French wrote:
>>
>> Hello, sorry that I cannot contribute directly to your solution, but in
>> the body of your email messsage you said all workstations start with a
>> *#*, did you mean w?  The two characters on the keyboard are near each
>> other.
>>
>> --
>> Warron French
>>
>>
>> On Fri, Oct 21, 2016 at 4:05 PM,  wrote:
>>
>>> I have two custom facts and I have put each file in the directory for a
>>> single module.  Both facts get loaded onto my clients.
>>>
>>> The problem I am having is that each fact runs successfully when it is
>>> by itself, but when both run at the same time, the results aren't as
>>> expected.
>>>
>>> To test, I rename one fact as *.rb.bak, and then I get proper results.
>>> Switch to the other fact, again, proper results.  Remove .bak so they both
>>> run, results are wrong.
>>>
>>> Here are my .rb files.
>>>
>>> All of my servers start with the letter a and have either an aX or aXXX
>>> which describes their physical location.  All of the servers end with 5
>>> characters that describe the network they are on.  The remaining characters
>>> describe what the server does.
>>>
>>> All of my workstations start with a #.
>>>
>>> What seems to happen, is that when both facts are running, none of my
>>> servers start with "a" so all of my servers show up as workstations.
>>>
>>> It appears that 'location_code.slice! seems to run, so the prefix of my
>>> hostname is gone and the first letter appears to be the part of the
>>> hostname that describes the servers function.
>>>
>>> To test, I changed "a" in my code to "f" and my file server had the
>>> proper server_role of file.
>>>
>>> I don't understand why this happens as my variables are different
>>> between the two script
>>>
>>> I appreciate any assistance.
>>>
>>> require 'facter'
>>>
>>> Facter.add(:location_code) do
>>>   setcode do
>>> address = Facter.value(:ipaddress).tr('.', '')
>>> address = address.to_i
>>> location_code = Facter.value(:hostname)
>>>   if address.between?(104127100, 104127255)
>>> location_code.slice!(0,2)
>>>   else
>>> location_code.slice!(0,4)
>>>   end
>>>   end
>>> end
>>>
>>>
>>>
>>>
>>> require 'facter'
>>>
>>> Facter.add(:server_role) do
>>>   setcode do
>>> ip_address = Facter.value(:ipaddress).tr('.', '')
>>> ip_address = ip_address.to_i
>>> server_role = Facter.value(:hostname)
>>> if server_role[0,1] != "a"
>>>   server_role = 'workstation'
>>> else
>>>   if ip_address.between?(104127100, 104127255)
>>> server_role.slice!(0,2)
>>> else
>>> server_role.slice!(0,4)
>>> end
>>> server_role = server_role[0..-6]
>>> end
>>>   end
>>> end
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Puppet Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to puppet-users...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/puppet-users/f0e17cd7-6179-4607-ab87-870bed5c4040%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/puppet-users/c2b30a49-5c0c-4281-82db-d9e58c15f650%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAJdJdQkOxnhVvOjfxfHx13-oq%2BKAHXBp3%2BuxwvjEL2aqBzDv8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Two Facter files seem to conflict

2016-10-21 Thread aarb000
Actually I meant that all of my workstations begin with a number.  

Thank you.

On Friday, October 21, 2016 at 3:40:48 PM UTC-5, Warron French wrote:
>
> Hello, sorry that I cannot contribute directly to your solution, but in 
> the body of your email messsage you said all workstations start with a *#*, 
> did you mean w?  The two characters on the keyboard are near each other.
>
> --
> Warron French
>
>
> On Fri, Oct 21, 2016 at 4:05 PM,  wrote:
>
>> I have two custom facts and I have put each file in the directory for a 
>> single module.  Both facts get loaded onto my clients.
>>
>> The problem I am having is that each fact runs successfully when it is by 
>> itself, but when both run at the same time, the results aren't as expected.
>>
>> To test, I rename one fact as *.rb.bak, and then I get proper results.  
>> Switch to the other fact, again, proper results.  Remove .bak so they both 
>> run, results are wrong.
>>
>> Here are my .rb files.
>>
>> All of my servers start with the letter a and have either an aX or aXXX 
>> which describes their physical location.  All of the servers end with 5 
>> characters that describe the network they are on.  The remaining characters 
>> describe what the server does.
>>
>> All of my workstations start with a #.
>>
>> What seems to happen, is that when both facts are running, none of my 
>> servers start with "a" so all of my servers show up as workstations.
>>
>> It appears that 'location_code.slice! seems to run, so the prefix of my 
>> hostname is gone and the first letter appears to be the part of the 
>> hostname that describes the servers function.
>>
>> To test, I changed "a" in my code to "f" and my file server had the 
>> proper server_role of file.
>>
>> I don't understand why this happens as my variables are different between 
>> the two script
>>
>> I appreciate any assistance.
>>
>> require 'facter'
>>
>> Facter.add(:location_code) do
>>   setcode do
>> address = Facter.value(:ipaddress).tr('.', '')
>> address = address.to_i
>> location_code = Facter.value(:hostname)
>>   if address.between?(104127100, 104127255)
>> location_code.slice!(0,2)
>>   else
>> location_code.slice!(0,4)
>>   end
>>   end
>> end
>>
>>
>>
>>
>> require 'facter'
>>
>> Facter.add(:server_role) do
>>   setcode do
>> ip_address = Facter.value(:ipaddress).tr('.', '')
>> ip_address = ip_address.to_i
>> server_role = Facter.value(:hostname)
>> if server_role[0,1] != "a"
>>   server_role = 'workstation'
>> else
>>   if ip_address.between?(104127100, 104127255)
>> server_role.slice!(0,2)
>> else
>> server_role.slice!(0,4)
>> end
>> server_role = server_role[0..-6]
>> end
>>   end
>> end
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Puppet Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to puppet-users...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/puppet-users/f0e17cd7-6179-4607-ab87-870bed5c4040%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/c2b30a49-5c0c-4281-82db-d9e58c15f650%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Two Facter files seem to conflict

2016-10-21 Thread warron.french
Hello, sorry that I cannot contribute directly to your solution, but in the
body of your email messsage you said all workstations start with a *#*, did
you mean w?  The two characters on the keyboard are near each other.

--
Warron French


On Fri, Oct 21, 2016 at 4:05 PM,  wrote:

> I have two custom facts and I have put each file in the directory for a
> single module.  Both facts get loaded onto my clients.
>
> The problem I am having is that each fact runs successfully when it is by
> itself, but when both run at the same time, the results aren't as expected.
>
> To test, I rename one fact as *.rb.bak, and then I get proper results.
> Switch to the other fact, again, proper results.  Remove .bak so they both
> run, results are wrong.
>
> Here are my .rb files.
>
> All of my servers start with the letter a and have either an aX or aXXX
> which describes their physical location.  All of the servers end with 5
> characters that describe the network they are on.  The remaining characters
> describe what the server does.
>
> All of my workstations start with a #.
>
> What seems to happen, is that when both facts are running, none of my
> servers start with "a" so all of my servers show up as workstations.
>
> It appears that 'location_code.slice! seems to run, so the prefix of my
> hostname is gone and the first letter appears to be the part of the
> hostname that describes the servers function.
>
> To test, I changed "a" in my code to "f" and my file server had the proper
> server_role of file.
>
> I don't understand why this happens as my variables are different between
> the two script
>
> I appreciate any assistance.
>
> require 'facter'
>
> Facter.add(:location_code) do
>   setcode do
> address = Facter.value(:ipaddress).tr('.', '')
> address = address.to_i
> location_code = Facter.value(:hostname)
>   if address.between?(104127100, 104127255)
> location_code.slice!(0,2)
>   else
> location_code.slice!(0,4)
>   end
>   end
> end
>
>
>
>
> require 'facter'
>
> Facter.add(:server_role) do
>   setcode do
> ip_address = Facter.value(:ipaddress).tr('.', '')
> ip_address = ip_address.to_i
> server_role = Facter.value(:hostname)
> if server_role[0,1] != "a"
>   server_role = 'workstation'
> else
>   if ip_address.between?(104127100, 104127255)
> server_role.slice!(0,2)
> else
> server_role.slice!(0,4)
> end
> server_role = server_role[0..-6]
> end
>   end
> end
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/puppet-users/f0e17cd7-6179-4607-ab87-870bed5c4040%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAJdJdQ%3DzuVASYPjuoQZHw5xpN_31PrH20jm5WDbnrdj7Y99t0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.