Puppet File Configuration Example


1) Create a new directory or file (with content)

node “UT-9c8e99e3959e”{
file { “/tmp/test_directory”:
ensure => “directory”,
owner  => “root”,
group  => “root”,
mode   => 755,}
file { “/tmp/test_directory/test_file”:
ensure => “present”,
content => “puppet test”

owner  => “jchen”,
group  => “jchen”,
mode   => 755,}
}

Example:

generic@UT-9c8e99e3959e:/tmp$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1361599286’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/File[/tmp/test_directory]/ensure: created
notice: /Stage[main]//Node[ut-9c8e99e3959e]/File[/tmp/test_directory/test_file]/ensure: created
notice: Finished catalog run in 0.02 seconds

generic@UT-9c8e99e3959e:/tmp$ ls -lhR test*
test_directory:
total 0
-rwxr-xr-x 1 jchen jchen 0 Feb 23 17:01 test_file

2) Create a symbolic link

node “UT-9c8e99e3959e”{
file { ‘/tmp/test1’:
ensure => ‘link’,
target => ‘/tmp/test_directory/test_file’,}
}

Example:

generic@UT-9c8e99e3959e:/tmp$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1361600008’
notice: /Stage[main]//Node[ut-9c8e99e3959e]/File[/tmp/test1]/ensure: created
notice: Finished catalog run in 0.02 seconds
generic@UT-9c8e99e3959e:/tmp$ ls -lh test1
lrwxrwxrwx 1 root root 29 Feb 23 17:14 test1 -> /tmp/test_directory/test_file

3) Remove a file

node “UT-9c8e99e3959e”{
file { “/tmp/test_directory/test_file”:
ensure => “absent”}
}

Example:

generic@UT-9c8e99e3959e:/tmp/test_directory$ ls
test_file

generic@UT-9c8e99e3959e:/tmp/test_directory$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1361666594’
info: FileBucket adding {md5}d41d8cd98f00b204e9800998ecf8427e
info: /Stage[main]//Node[ut-9c8e99e3959e]/File[/tmp/test_directory/test_file]: Filebucketed /tmp/test_directory/test_file to puppet with sum d41d8cd98f00b204e9800998ecf8427e
notice: /Stage[main]//Node[ut-9c8e99e3959e]/File[/tmp/test_directory/test_file]/ensure: removed
notice: Finished catalog run in 0.04 seconds

generic@UT-9c8e99e3959e:/tmp/test_directory$ ls
generic@UT-9c8e99e3959e:/tmp/test_directory$

4) Backup a file to the central server before replace it

– Add access permission in the auth.conf file

path /file
auth any
allow *

– Specify the folder in fileserver.conf

[files]
path /var/lib/puppet/files
allow *

– Configurations in the site.pp file (Backup wfclient.ini to the bucket folder in Puppet server, then replace it with the one in the files folder)

filebucket { “main”:
server => “puppet.my.lab”,
path => false,
}

node “UT-9c8e99e3959e”{
file { “/opt/Citrix/ICAClient/config/wfclient.ini”:
source => “puppet:///files/wfclient.ini”,
backup => “main”,}
}

Example:

generic@UT-9c8e99e3959e:/opt/Citrix/ICAClient/config$ sudo puppet agent –test
info: Caching catalog for ut-9c8e99e3959e
info: Applying configuration version ‘1361664674’
info: /Stage[main]//Node[ut-9c8e99e3959e]/File[/opt/Citrix/ICAClient/config/wfclient.ini]: Filebucketed /opt/Citrix/ICAClient/config/wfclient.ini to main with sum bdc85f14bc448a415df22dfd9902510a
notice: /Stage[main]//Node[ut-9c8e99e3959e]/File[/opt/Citrix/ICAClient/config/wfclient.ini]/ensure: defined content as ‘{md5}748e8008b3362a7c48fa0e92920015a0’
notice: Finished catalog run in 64.79 seconds

generic@UT-9c8e99e3959e:/opt/Citrix/ICAClient/config$ head wfclient.ini

;********************************************************************
;
;    wfclient.ini
;
;    User configuration for Citrix Receiver for Unix
;
;    Copyright 1994-2006, 2009 Citrix Systems, Inc. All rights reserved.
;
;    puppet test file: new version

Advertisement

One thought on “Puppet File Configuration Example

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s