Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Puppet Cookbook - Third Edition
  • Toc
  • feedback
Puppet Cookbook - Third Edition

Puppet Cookbook - Third Edition

By : Thomas Uphill, John Arundel
5 (2)
close
Puppet Cookbook - Third Edition

Puppet Cookbook - Third Edition

5 (2)
By: Thomas Uphill, John Arundel

Overview of this book

This book is for anyone who builds and administers servers, especially in a web operations context. It requires some experience of Linux systems administration, including familiarity with the command line, file system, and text editing. No programming experience is required.
Table of Contents (12 chapters)
close
11
Index

Using array iteration in templates


In the previous example, we saw that you can use Ruby to interpolate different values in templates depending on the result of an expression. But you're not limited to getting one value at a time. You can put lots of them in a Puppet array and then have the template generate some content for each element of the array using a loop.

How to do it…

Follow these steps to build an example of iterating over arrays:

  1. Modify your site.pp file as follows:

      node 'cookbook' {
        $ipaddresses = ['192.168.0.1', '158.43.128.1', '10.0.75.207' ]
        file { '/tmp/addresslist.txt':
          content => template('base/addresslist.erb')
        }
      }
  2. Create the file modules/base/templates/addresslist.erb with the following contents:

    <% @ipaddresses.each do |ip| -%>
    IP address <%= ip %> is present
    <% end -%>
  3. Run Puppet:

    [root@cookbook ~]# puppet agent -t
    Info: Caching catalog for cookbook.example.com
    Info: Applying configuration version '1412141917'
    Notice: /Stage[main...
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete