Ask Your Question
0

How do I define the directory in init.pp?

asked 2016-03-18 15:07:41 -0500

JamesHailey gravatar image

My init.pp looks like below:

class checkout {
 file { '/etc/example/test/testcv.sh':
 ensure   => present,
    owner => 'root',
    mode => '0755',
    content => template('checkout/testcv.sh.erb')
    }
}

What this does is, copies testcv.sh to my /etc/example/test/ in all my hosts automatically. But if I have to copy the directory to the certain location what resource type should I use? I tried replacing file with "dir" but it didn't work.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2016-03-20 09:01:28 -0500

updated 2016-03-20 19:29:08 -0500

It's unclear as to whether you're trying to create a directory, or recursively mirror the contents of a directory.

If you just want to create a directory:

file { '/etc/httpd/conf.d':
  ensure => directory,
}

If you need to recursively mirror the contents of a directory:

file { '/etc/httpd/conf.d':
  source  => 'puppet://server/vol/mnt1/adm/httpd/conf.d',
  recurse => true,
}

For example:

/tmp/foo.pp

file { '/tmp/mydir':
  source  => 'puppet:///modules/profile/mydir',
  recurse => true,
}

Then:

[root@centos-72-x64 ~]# mkdir -p /etc/puppetlabs/code/environments/production/modules/profile/files/mydir
[root@centos-72-x64 ~]# for i in a b c d ; do touch /etc/puppetlabs/code/environments/production/modules/profile/files/mydir/$i ; done 
[root@centos-72-x64 ~]# puppet apply /tmp/foo.pp 
Notice: Compiled catalog for centos-72-x64.macquarie.local in environment production in 0.04 seconds
Notice: /Stage[main]/Main/File[/tmp/mydir]/ensure: created
Notice: /Stage[main]/Main/File[/tmp/mydir/a]/ensure: defined content as '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: /Stage[main]/Main/File[/tmp/mydir/b]/ensure: defined content as '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: /Stage[main]/Main/File[/tmp/mydir/c]/ensure: defined content as '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: /Stage[main]/Main/File[/tmp/mydir/d]/ensure: defined content as '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: Applied catalog in 0.21 seconds
edit flag offensive delete link more

Comments

I wanted to recursively copy(mirror) the directory. I am assuming that's my init.pp. But how do I execute the copy command? I need the puppet to automatically copy my directory recursively from master to a certain location in all the hosts. Plus any other parameter to define?

JamesHailey gravatar imageJamesHailey ( 2016-03-20 10:32:07 -0500 )edit

You don't execute a copy command; the puppet agent will download the contents from the location specified in source when the catalog is applied. I don't think there any other mandatory parameters. I haven't used this feature; let us know how it goes.

Alex Harvey gravatar imageAlex Harvey ( 2016-03-20 10:40:07 -0500 )edit

Thing that's confusing me is I don't see it defined what and where it should be copied to. My directory name is 'puppetest' in master and I want to copy it to '/etc/example/' in each host. The directory will be updated frequently and I want it to be auto. pushed to hosts. Am I missing something?

JamesHailey gravatar imageJamesHailey ( 2016-03-20 10:56:27 -0500 )edit

Plus do I need to make any changes on conf.d as you mentioned there?

JamesHailey gravatar imageJamesHailey ( 2016-03-20 10:59:22 -0500 )edit

/etc/httpd/conf.d is just an example. In my example, the contents at puppet://server/vol/mnt1/adm/httpd/conf.d would be synced to /etc/httpd/conf.d on each host.

Alex Harvey gravatar imageAlex Harvey ( 2016-03-20 11:25:39 -0500 )edit
0

answered 2016-03-18 17:34:27 -0500

UBPClaw gravatar image

updated 2016-03-18 17:54:57 -0500

Puppet will only manage what you explicitly tell it to manage. In your example above youd need a file resource for /etc/example and a second file resource for /etc/example/test before finally deploying your shell script.

class checkout {

file { '/etc/example': ensure => directory, before => file['/etc/example/test'] }

file { '/etc/example/test': ensure => directory, before => file['/etc/example/test/testcv.sh'] }

file { '/etc/example/test/testcv.sh': ensure => present, mode => '0755', content => "Hello World", } }

edit flag offensive delete link more
0

answered 2016-03-18 17:51:52 -0500

lavaman gravatar image

You create directories with file resources, but setting ensure to directory:

http://docs.puppetlabs.com/puppet/lat...

edit flag offensive delete link more

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

Stats

Asked: 2016-03-18 15:07:41 -0500

Seen: 248 times

Last updated: Mar 20 '16