Ask Your Question
0

update line if found in file

asked 2017-06-26 22:16:31 -0500

MarkV gravatar image

I am trying to figure out how to replace a line in a file, but only if it already exists in the file.

eg, i only want to update the proxy where it is already configured in /etc/yum.conf

this is what i am trying, but i cant seem to make it work

file_line { 'yum_proxy':
  ensure           => 'present',
  path             => '/etc/yum.conf',
  line             => 'proxy=http://new.proxy.address:8080', 
  match            => '^proxy\=',
 match_for_absence => 'false',
}

is there any way in which I can do this ?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-07-07 12:02:33 -0500

updated 2017-07-07 14:39:11 -0500

DarylW gravatar image

.

  file_line { 'fred':
        ensure           => 'present',
        path             => '/etc/yum.conf',
        line             => 'proxy=http://new.proxy.address:8080', 
        match            => '^proxy\=',
        replace    => true,
        match_for_absence => 'false',
    }

add the line replace as above - should work ok.

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

Stats

Asked: 2017-06-26 22:16:31 -0500

Seen: 37 times

Last updated: Jul 07