Puppet - Fact Conditionals

 Exercise  - Fact Conditionals

 Go to agent terminal window and run the following command

facter

 This will display the facts gathered from the agent node by the factor application running with Puppet

 Go to the master terminal and create a file factconditional.pp and add the following

nano factconditionals.pp

if $::operatingsystem == ‘Ubuntu’ {

notify {‘Installing on Ubuntu’:}

}

 Go to the master terminal and run this command.

puppet apply factconditionals.pp

 Go to the master terminal and update ap factconditionals.pp to add the following

nano factconditionals.pp

if $::operatingsystem == ‘Ubuntu’ {

notify {‘Installing on Ubuntu in if statement’:}

}

case $::operatingsystem {

‘Ubuntu’: {

notify {‘Installing on Ubuntu in case’:}

}

‘RedHat’: {

notify {‘Installing on Red Hat’:}

}

}

 Go to the master terminal and run this command.

puppet apply factconditionals.pp

 You will see that Puppet has applied the case statement install first and then the if statement. When there are no relational dependencies between different statements Puppet decides which condition, it wants to apply first based on the most efficient installation and no necessarily on the order in which its written in your manifest.

 If there are relational dependencies between statements then it applies in the order they are mentioned in the manifest.

nano conditionals.pp

case $my_variable {

‘One’: {

notify {‘The value of my variable is One’:}

}

default: {

{“The value of my variable is $my_variable in the case statement”:}

}

}

Comments

Popular posts from this blog

Terraform

Scrum Master Interview help - Bootcamp

Kubernetes