Ask Your Question
0

Change multiple lines in file with unknown text

asked 2018-06-01 05:31:27 -0600

daniel.serrao gravatar image

Hi,

I have a file with a text like:

[email]
footer.text = aaaaaaaaaaaaaaaaaaaaa\
\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
\
ccccccccccccccccccccccccccccccccc

mailserver = mailserver.com

In this case the footer.text and the mailserver are 'keys' and the 'values' are on the right side of the '='. This was being done by using the ini_setting like this:

    ini_setting { "[${filepath}] [${section}] ${key}":
      path    => $filepath,
      section => $section,
      setting => $key,
      value   => $value,
    }

The $value would be something like:

aaaaaaaaaaaaaaaaaaaaa\\ \n
\\ \n
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\\ \n
\\ \n
ccccccccccccccccccccccccccccccccc

Puppet generates the correct text in the file, but the problem is that puppet only check and replace the first line on the rightof the '='. This means that at the end, the text below the first line is duplicated and I get this:

[email]

footer.text = aaaaaaaaaaaaaaaaaaaaa\
\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
\
ccccccccccccccccccccccccccccccccc
\
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\
\
ccccccccccccccccccccccccccccccccc

mailserver = mailserver.com

My intention is to replace all the text. I thought about using the resource 'file_line' and use the parameter 'match' to do this, but it wouldn't work since this text can be changed. What I need puppet to do is to replace all the text from '=' until the next key, in this case until the 'mailserver'.

Is there a way to do this?

edit retag flag offensive close merge delete

Comments

I don't believe a multiline 'value' is 'in spec' for an inifile, though there isn't really a strongly defined standard.

DarylW gravatar imageDarylW ( 2018-06-18 08:25:02 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-06-15 10:15:07 -0600

daniel.serrao gravatar image

Basically my solution was to manage the all file using the file resource.

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: 2018-06-01 05:31:27 -0600

Seen: 412 times

Last updated: Jun 15