Ask Your Question
0

add a line using file_line in a specific sequence if line does not exist

asked 2018-05-08 01:24:29 -0600

Daizy gravatar image

Hello,

I tried to modify the config file of UiPath Studio after it gets installed on a machine using manifest. I am trying to add the line mentioned below in the config file in my manifest -

file_line { 'ModifyUiPathRobotConfFile':
        path => 'C:\Program Files (x86)\UiPath Studio\UiRobot.exe.config',  
        line => '  <runtime>
    <generatePublisherEvidence enabled="false"/>',
        match   => "<runtime>",

The problem is whenever the manifest is executed again on the machine, the line which I have mentioned above gets added in the config file every time. Can anyone suggests how to cure this error?

the line should be added in '<runtime>' sequence in the config file -

<runtime>
    <generatePublisherEvidence enabled="false"/>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</runtime>

Whenever the manifest gets executed, the line is getting overwritten again n again -

<runtime>
    <generatePublisherEvidence enabled="false"/>
    <generatePublisherEvidence enabled="false"/>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</runtime>
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-05-08 14:00:14 -0600

binford2k gravatar image

You're trying to replace a single line with multiple lines. The problem is that that your regex also matches a line after adding the new value, so Puppet happily replaces it again. Sometimes you can make this work by setting the multiple attribute to match multiple lines, but generally you'll be much better off with just managing the whole file instead of trying to modify it in place.

edit flag offensive delete link more

Comments

1

I always feel that file_line is a 'poor mans sed' that tends to cause more headaches then it saves... You may also be able to use augeas to turn the xml structure into a tree and do a count style replacement, but that is probably just as fraught for problems..

DarylW gravatar imageDarylW ( 2018-05-08 14:37:34 -0600 )edit
0

answered 2018-05-10 01:32:07 -0600

Daizy gravatar image

I tried using 'multiple' attribute but it is not working here in this case. What is happening here is '<runtime>' keyword is already written in the configuration file of the application. The query which I am giving is matching and replacing '<runtime>' keyword with

 '  <runtime>
    <generatePublisherEvidence enabled="false"/>'

line. I just want to add generatePublisherEvidence line in config file but I have to write the whole line else I don't know how will I be able to use match parameter.

file_line { 'ModifyUiPathRobotConfFile':
        path => 'C:\Program Files (x86)\UiPath Studio\UiRobot.exe.config',  
        line => '  <runtime>
    <generatePublisherEvidence enabled="false"/>',
        match   => "<runtime>",

So whenever the manifest is implemented on machine, every time, '<runtime>' gets replaced with the above mentioned line, and so line

`'<generatePublisherEvidence enabled="false"/>

which was added in the first run of the manifest after runtime, stays in config file, while again the same line keeps on getting added (replacing runtime keyword).

The output of config file then contains multiple generatePublisherEvidence lines. I want that if the lines already exists, don't add the line.

edit flag offensive delete link more

Comments

with 'multiple' you would still need to make your detection not find something that the next piece is adding in. Something like matching the line after runetime being NOT what you are adding in, that way it will be idempotent.

DarylW gravatar imageDarylW ( 2018-05-11 07:20:04 -0600 )edit

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-05-08 01:24:29 -0600

Seen: 188 times

Last updated: May 10