Ask Your Question

serverspec file_line and hiera value array

asked 2015-12-14 05:42:49 -0600

Chutki gravatar image


I have below two manifests in puppet, I have few challenges when I use serverspec tests.


file_line { 'functions':
    ensure => present,
    path   => '/etc/functions',
    line   => 'umask 009',
    match  => '^umask.*$',

I tried below snippet for serverspec

describe file('/etc/init.d/functions') do
  its(:content) { should match 'umask' }
  its(:value) { should eq '027' }

but getting below error

Failure/Error: its(:value) { should eq '027' }
       undefined method `value' for File "/etc/functions":Serverspec::Type::File
require 'spec_helper'

how I can check in configuration file "/etc/functions" the value 009 updated correctly by using the serverspec.

2) This is for hiera in puppet, below is a basic package installation in puppet

class packages {

  $pack_array = hiera_array('list')

  package { $pack_array : ensure => installed }

I tried below server spec and its working

packages = ['ksh','unzip','wget','zip']

describe "Install Base Packages" do

  packages.each do|base|
    describe package(base) do
      it { should be_installed }


puppet manifest takes "list" values from yaml file. Is there any option in the server spec that we can pass array values from a yaml file like how we do it in rspec-puppet.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-12-14 12:07:23 -0600

lavaman gravatar image

updated 2015-12-14 12:09:04 -0600

There is no key/value matcher for the contents of a file. If you expect a file to contain a line that says 'umask 027' you should simply set the content value to what you expect.

Serverspec tests are just ruby code, so you can include the ruby yaml library and read in anything you want from a yaml file.

edit flag offensive delete link more


For Yaml. I tried ruby as suggested by you and it worked. For file_line, I set content value like "its(:content) { should match "umask 02" }" but my test case passed. But my actual configuration fale value is "umask 027". So why my test case didn't file if there is misatch.

Chutki gravatar imageChutki ( 2015-12-15 05:32:28 -0600 )edit

Putting a string there just does a simple text matching. It passes because the text does in fact exist in the file. If you want to check that the entire line matches, you need to use a regex instead of a string: its(:content) { should match /^umask 027$/ } or something similar.

lavaman gravatar imagelavaman ( 2015-12-15 12:59:29 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2015-12-14 05:42:49 -0600

Seen: 404 times

Last updated: Dec 14 '15