Greens Technologys Whatsapp
Greens Technologys Whatsapp
Blog

Puppet in DevOps   (5.0)  |   65,984 Ratings

Iteration in Templates

Puppet template also supports array iteration. If the variable one is accessing is an array, then one can iterate over it.

$values = [val1, val2, otherval]

We can have templates like the following.

<% values.each do |val| -%>
Some stuff with <%= val %>
<% end -%>

The above command will produce the following result.

Some stuff with val1
Some stuff with val2
Some stuff with otherval

Conditions in Templates

The erb templating supports conditionals. The following construct is a quick and easy way to conditionally put a content in a file.

<% if broadcast != "NONE" %> broadcast <%= broadcast %> <% end %>

Templates and Variables

One can use templates to fill in variables in addition to filling out the file content.

testvariable = template('/var/puppet/template/testvar')

Undefined Variable

If one needs to check if the variable is defined before using it, the following command works.

<% if has_variable?("myvar") then %>
myvar has <%= myvar %> value
<% end %>

Out of Scope Variable

One can look for out of scope variable explicitly with the lookupvar function.

<%= scope.lookupvar('apache::user') %>

Sample Project Template

<#Autogenerated by puppet. Do not edit.
[default]
#Default priority (lower value means higher priority)
priority = <%= @priority %>
#Different types of backup. Will be done in the same order as specified here.
#Valid options: rdiff-backup, mysql, command
backups = <% if @backup_rdiff %>rdiff-backup,
<% end %><% if @backup_mysql %>mysql,
<% end %><% if @backup_command %>command<% end %>
<% if @backup_rdiff -%>

[rdiff-backup]
<% if @rdiff_global_exclude_file -%>
global-exclude-file = <%= @rdiff_global_exclude_file %>
<% end -%>
<% if @rdiff_user -%>
user = <%= @rdiff_user %>
<% end -%>
<% if @rdiff_path -%>
path = <%= @rdiff_path %>
<% end -%>

#Optional extra parameters for rdiff-backup
extra-parameters = <%= @rdiff_extra_parameters %>
#How long backups are going to be kept
keep = <%= @rdiff_keep %>
<% end -%>
<% if @backup_mysql -%>%= scope.lookupvar('apache::user') %>

[mysql]
#ssh user to connect for running the backup
sshuser = <%= @mysql_sshuser %>
#ssh private key to be used
sshkey = <%= @backup_home %>/<%= @mysql_sshkey %>
<% end -%>
<% if @backup_command -%>
[command]

#Run a specific command on the backup server after the backup has finished
command = <%= @command_to_execute %>
<% end -%>

DevOps training and Placement

Gani is a professional agile coach and Certified Scrum Developer (CSD) trainer. He is having 11 years of experience in software development and have worked with many organizations and on multiple technology stacks including .Net/C#, Java, Ruby, Python and JavaScript etc. Gani is Certified LeSS (Large-Scale Scrum) Practitioner and have helped organizations is agile adoption. He is one of the early adopter of DevOps practices and teaches DevOps culture, practices and tools to development team and operation team.


Best DevOps Training Institute in Chennai with the most experienced and DevOps certified expert trainers in the field. Greens Technology provides DevOps training and certification in Chennai to professionals and corporates on Deployment and automation using devops tools

For Chennai Branches
Adyar - +91 89399 15577
OMR - +91 89399 25577
Velachery - +91 89399 15577
Tambaram - +91 89399 25577

QuickEnquiry



Our Reviews 5 Star Rating: Recommended - Best IT Training in Chennai

5  out of 5  based on 12263 ratings.

Google          5 Star Rating: Recommended - Best IT Training in Chennai

Facebook      5 Star Rating: Recommended - Best IT Training in Chennai

UrbanPro       5 Star Rating: Recommended - Best IT Training in Chennai

Sulekha         5 Star Rating: Recommended - Best IT Training in Chennai

Yet5              5 Star Rating: Recommended - Best IT Training in Chennai

Justdial          5 Star Rating: Recommended - Best IT Training in Chennai



Top Courses



RelatedTrainings