Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

my question for the manifest file, pls explain

The Manifest file looks like below

my initial version looks like:

node ;slave1'{

if ['/bin/which apache2']{

include 'docker'

}

Elsif ['/bin/which nginx']{

include 'java'

}

else {

file{'/tmp/hello.txt':

content=> "nothing found",

mode=> '0644',

}

}

}

node 'slave2'{

if ['/bin/which nginx']{

include 'java'

}

Elsif ['/bin/which apache2']{

include 'docker'

}

else {

file{'/tmp/hello.txt':

content=> "nothing found",

mode=> '0644',

}

}

}

I have simplified the above file and it looks like:

node default{

if ['/bin/which apache2']{

include 'docker'

}

if ['/bin/which nginx']{

include 'java'

}

else {

file{'/tmp/hello.txt':

content=> "nothing found",

mode=> '0644',

}

}

}

I tried to simplify the code and make it generic so that it can run in any node and check the case and install the respective version. but after I changed like this, it only checks the if condition and does not go to else condition, it just installs docker on both the slaves

I tried to reverse the code then it just installs Java-- Not sure how to rewrite it

I even tried to modify the original manifest file of slave2 bu changing the apache2 at the beginning then, only docker gets installed

I want to know how exactly the if and elsif conditions are checked?

1 Answer

0 votes
by (50.2k points)

As your code is perfectly fine but here the issue with this puppet if and else-if statements are:

Puppet’s “if” statements behave much like those in any other language. The if condition is evaluated first and, if it is true, only the if code block is executed. If it is false, each elsif condition (if present) is tested in order, and if all conditions fail, the else code block (if present) is executed.

So that is the reason for your nodes don’t install your required tools. If you want to check then make the if statement false and then you can get else/elseif statements being executed. 

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
asked Mar 7, 2020 in DevOps and Agile by chandra (29.3k points)

Browse Categories

...