How can we add multiple lines to a file ?

2,522 views
Skip to first unread message

Vikas Kumar

unread,
Aug 12, 2014, 2:57:14 AM8/12/14
to puppet...@googlegroups.com
Hello,

I am looking for an option to add multiple lines to a /etc/bashrc and /etc/profile. I can do this with file_line, but is there any other alternative. file_line does the job but for each line I will have to create a file_line resource, which does not sound good for multiple lines.

Regards,
Vikas

Sijis Aviles

unread,
Aug 12, 2014, 12:49:47 PM8/12/14
to puppet...@googlegroups.com

Vikas,

Maybe try using concat module (https://github.com/puppetlabs/puppetlabs-concat)? But i think you'll still have multiple concat::fragment entries.

Sijis

Lakshmi Thampi

unread,
Jan 27, 2015, 1:40:49 AM1/27/15
to puppet...@googlegroups.com
Could you please tell me which of the solutions worked in this case
As i am also trying to do the same
I am trying to do it with concat like this for /etc/profile file editing

class postgresql::profilechange{

include concat::setup

concat { '/etc/profile':

  mode  => '0775',

  owner => 'root',

  group => 'root',

  ensure => present,


}


concat::fragment { 'file04_fa':

  target  => '/etc/profile',

  content => "PATH=$PATH:/usr/local/pgsql/bin\n",

  order => 01

}


}

But it is giving me this error
---------------------------------------------------

Info: Retrieving plugin

Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/puppet_vardir.rb

Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/facter_dot_d.rb

Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/root_home.rb

Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/pe_version.rb

Info: Loading facts in /etc/puppet/modules/concat/lib/facter/concat_basedir.rb

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class concat::setup for sys-server on node sys-server

Warning: Not using cache on failed catalog

Error: Could not retrieve catalog; skipping run

Any pointers are appreciated

jcbollinger

unread,
Jan 28, 2015, 9:55:01 AM1/28/15
to puppet...@googlegroups.com


On Tuesday, August 12, 2014 at 1:57:14 AM UTC-5, Vikas Kumar wrote:
Hello,

I am looking for an option to add multiple lines to a /etc/bashrc and /etc/profile. I can do this with file_line, but is there any other alternative. file_line does the job but for each line I will have to create a file_line resource, which does not sound good for multiple lines.


If all the lines you want to add are available from one source, then you could join them with semicolons and add them as one line.

Alternatively, some Linux distributions (RedHat-family distros for sure) ship with a built-in mechanism for this.  On CentOS, for example, both /etc/profile and /etc/bashrc process shell code from each and every file in /etc/profile.d/*.sh.  On such systems, you can inject your own code into the shell configuration by dropping a world-readable file of whatever length you want into /etc/profile.d.  This is incredibly useful.

If your systems are not built that way by default then you can use a File_line to insert a (complex) one-liner into /etc/profile and /etc/bashrc to enable such a feature, and then proceed as above.


John

Vikas Kumar

unread,
Jan 28, 2015, 10:16:36 AM1/28/15
to puppet...@googlegroups.com
Hi Laxmi,

I could not find a way out to add multiple lines. I did this, which served my purpose. May be it is not suitable for your requirement.

     file { "/etc/mytweaks":
      owner   => 'root',
      group   => 'root',
      mode    => '0755',
      source => "puppet:///modules/tweaks-history_shellprompt/mytweaks",
     }

     file_line { 'Adding-To-Bashrc':
      ensure => present,
      line => 'source /etc/mytweaks',
      path => "$bashrc_location",
     }

Regards,
Vikas
Reply all
Reply to author
Forward
0 new messages