Ask Your Question

Is it possible to create dir from array variable?

asked 2015-10-28 17:58:22 -0600

rgv gravatar image


I am trying to create bunch of directories under "/" and my code is as below:

file {

ensure  =>  directory,
owner   =>  elasticsearch,
group   =>  elasticsearch,
require =>  Package['elasticsearch'],


and hiera variable is

path_data: [ "/data1", "/data2", "/data3", "/data4", "/data5", "/data6", "/data7", "/data8" ]

but i am getting below error.

File[/data1/data2/data3/data4/data5/data6/data7/data8]/ensure: change from absent to directory failed: Cannot create /data1/data2/data3/data4/data5/data6/data7/data8; parent directory /data1/data2/data3/data4/data5/data6/data7 does not exist

Any help??


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-10-28 19:45:22 -0600

lupin gravatar image

updated 2015-10-30 12:37:00 -0600

Yes, file type can create directory and accept array in title.

file { $path_data:
  ensure => directory,
  mode => '0755',

Your hiera data should look like:

   - /data1
   - /data0
edit flag offensive delete link more

answered 2015-10-29 06:26:14 -0600

DarylW gravatar image

The reason you are getting the error you have is because you put your array inside double quotes. That interpolates it into a single string.

If you just use $pathdata instead of "${pathdata}", it will work as you expect.

edit flag offensive delete link more


Still not working, i am getting below error. Error: Failed to apply catalog: Parameter path failed on File[undef]: File paths must be fully qualified, not 'undef' at file { $path_data: ensure => directory, mode => '0755', recurse => true, }

rgv gravatar imagergv ( 2015-10-29 13:17:52 -0600 )edit

It looks like path_data is a top-level variable in hiera. In this case you will need to explicitly look it up with the hiera function. You only get auto-lookup for class parameters when using hiera.

lavaman gravatar imagelavaman ( 2015-10-29 18:06:33 -0600 )edit

I've appended the hiera data input format on you answer above.

lupin gravatar imagelupin ( 2015-10-29 23:59:31 -0600 )edit

Ah, I didn't realize you used the 'puppet syntax' for your array in your hiera file instead of the hiera array syntax. See lupin's answer above.

DarylW gravatar imageDarylW ( 2015-10-30 07:19:44 -0600 )edit

the syntax the OP used in the original post will work fine in the hiera data file. He just needs to pull it in via `$path_data = hiera('path_data', [])`

JohnsonEarls gravatar imageJohnsonEarls ( 2015-10-30 12:40:48 -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

1 follower


Asked: 2015-10-28 17:58:22 -0600

Seen: 213 times

Last updated: Oct 30 '15