Search code examples
puppet

How to set environment variables in Ubuntu OS using Puppet


I have been learning Puppet since two weeks and would like to automate few of our routine tasks. As a part of web application setup, first of all we have to set environment variables for JAVA, ANT etc. in the /homeuser/.bashrc file.

I have written the following manifests for it to set path and home variables and take it effect with out a reboot :

class bashrc {

file { "bashrc file":
    path => "/root/.bashrc",
    source  => "/mnt/bashrc",
    owner   => "root",
    group   => "root",
    mode    => "0644",
     }

exec { "root_bashrc":
    command     => "source  /root/.bashrc'",
    cwd => "/root",
    provider => 'shell',
     }

}

the below is the out put of puppet run :

 root@liferay:/mnt# sudo puppet apply bash.pp
Notice: Compiled catalog for liferay in environment production in 0.03 seconds
Notice: Finished catalog run in 14.74 seconds
root@liferay:/mnt#

The .bashrc file is not getting updated after Puppet run. Please help us how to set environment variables and should get reflected with out reboot using Puppet.


Solution

  • You have only defined bashrc class. To execute code of the class you must instance it. The recommended way to do that is to add:

    include bashrc
    

    to some manifest. More about class instantiation here.

    To modify content of bashrc file you use augeas resource. Here you have guide how to use it.