Ask Your Question
0

why serverspec compare all if conditions for os family

asked 2015-12-18 08:15:44 -0500

Chutki gravatar image

Hi

I have below serverspec tests for puppet testing, its testing all the if condition, though my os belongs to rhel6

if os[:release] = 5

   describe file('/etc/modprobe.conf') do
    it { should exist }
 end

if os[:release] = 6
 describe file('/etc/modprobe.d/ipv6.conf') do
    it { should exist }
 end

if os[:release] = 7

  describe file('/etc/sysctl.d/disableipv6.conf') do
    it { should exist }
end

I have rhel6, so serverspec should test only if condition if os[:release] = 6 but its testing all if conditions.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-12-18 09:48:11 -0500

updated 2015-12-18 21:49:00 -0500

Here's a ruby script; read it, think about what you expect it would do when you run it, run it, and see if it does what you expected.

#!/usr/bin/ruby
os = {:release => 6}
if os[:release] = 5
  puts "os release is #{os[:release]}"
end
if os[:release] = 6
  puts "os release is #{os[:release]}"
end
if os[:release] = 7
  puts "os release is #{os[:release]}"
end

UPDATE

So the answer is the statement os[:release] = 5 is an assignment - it assigns the value of 5 to os[:release]. It also returns true in a boolean context, which can be confusing, if what you really meant was os[:release] == 5.

In fewer words, you used = when you meant == :)

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: 2015-12-18 08:15:44 -0500

Seen: 353 times

Last updated: Dec 18 '15