Bug #3293
closedIt is not possible to add a block content or at a specified location of a file using 'Enforce file content' Technique
Description
We should be able to specify where to add content in a file with the 'Enforce a file content' and to add a block.
Actually, if we have to add content like in the /etc/cups/printers.conf with group of parameters into a tag, this is not possible. Trying to add a group of parameters will not be functionnal and if one is not compliant, the line of the group of parameters will be added to the end of the file.
Updated by Jonathan CLARKE over 11 years ago
This sounds like a reasonable request, and would make profit of one of CFEngine's more powerful features in file editing.
What are the exact parameters you need to add to the existing Technique? I assume just "Insert this text after a line matching this regex"? Or something else. Let's discuss the spec here before attempting any implementation.
Updated by Nicolas PERRON over 11 years ago
- Status changed from New to Discussion
Jonathan CLARKE wrote:
In my opinion, it should be two parameters to be added.This sounds like a reasonable request, and would make profit of one of CFEngine's more powerful features in file editing.
What are the exact parameters you need to add to the existing Technique? I assume just "Insert this text after a line matching this regex"? Or something else. Let's discuss the spec here before attempting any implementation.
- Insert this text after a line matching this regex to be sure to add the configuration property in the right location
- Add as one entire block ? This could be usefull if an order is expected in the add of content.
Updated by Jonathan CLARKE over 11 years ago
Nicolas PERRON wrote:
Jonathan CLARKE wrote:
In my opinion, it should be two parameters to be added.This sounds like a reasonable request, and would make profit of one of CFEngine's more powerful features in file editing.
What are the exact parameters you need to add to the existing Technique? I assume just "Insert this text after a line matching this regex"? Or something else. Let's discuss the spec here before attempting any implementation.
- Insert this text after a line matching this regex to be sure to add the configuration property in the right location
Sounds great.
- Add as one entire block ? This could be usefull if an order is expected in the add of content.
This sounds to me like a separate feature: you seem to be implying that lines are not inserted in order currently. If so, that's a bug and should be filed in a separate ticket. Or is that not the case? If so, please clarify.
Updated by Nicolas PERRON over 11 years ago
Jonathan CLARKE wrote:
Nicolas PERRON wrote:
Jonathan CLARKE wrote:
In my opinion, it should be two parameters to be added.This sounds like a reasonable request, and would make profit of one of CFEngine's more powerful features in file editing.
What are the exact parameters you need to add to the existing Technique? I assume just "Insert this text after a line matching this regex"? Or something else. Let's discuss the spec here before attempting any implementation.
- Insert this text after a line matching this regex to be sure to add the configuration property in the right location
Sounds great.
Ok, then is this a new feature (user story to create) or this bug answer the problem ?
- Add as one entire block ? This could be usefull if an order is expected in the add of content.
This sounds to me like a separate feature: you seem to be implying that lines are not inserted in order currently. If so, that's a bug and should be filed in a separate ticket. Or is that not the case? If so, please clarify.
I'm not sure of this but I will test it. It seems to me that if just one line of the block defined is missing, it will be added to the end of the file which will not respect the initial order.
Updated by Nicolas PERRON over 11 years ago
- Assignee set to Jonathan CLARKE
Nicolas PERRON wrote:
Jonathan CLARKE wrote:
Nicolas PERRON wrote:
Jonathan CLARKE wrote:
[...]
- Add as one entire block ? This could be usefull if an order is expected in the add of content.
This sounds to me like a separate feature: you seem to be implying that lines are not inserted in order currently. If so, that's a bug and should be filed in a separate ticket. Or is that not the case? If so, please clarify.
I'm not sure of this but I will test it. It seems to me that if just one line of the block defined is missing, it will be added to the end of the file which will not respect the initial order.
In fact, If I define A Directive that the file /tmp/bug_3293.txt should contain this:
This is the line 1 This is the line 2 This is the line 3 This is the line 4 This is the line 5 This is the line 6 This is the line 7
If the file does not exist, all would be fine.
If the file contains:
#This is the starting comment This is the line 2 #Some comments there This is the line 4 This is the line 5 #Other comments appears This is the line 7 #This is the ending comment
The result will be:
#This is the starting comment This is the line 2 #Some comments there This is the line 4 This is the line 5 #Other comments appears This is the line 7 #This is the ending comment This is the line 1 This is the line 3 This is the line 6
The result is that lines has been added in order but still are not conform to the block defined in the Directive.
I suppose This is not really a bug but a new feature. What's your opinion, Jon ?
Updated by Matthieu CERDA over 11 years ago
- Target version changed from 2.3.11 to 2.3.12
Updated by Matthieu CERDA over 11 years ago
- Target version changed from 2.3.12 to 2.3.13
Updated by Nicolas PERRON over 11 years ago
- Target version changed from 2.3.13 to 84
Updated by Nicolas PERRON over 11 years ago
- Target version changed from 84 to 2.4.7
Updated by Nicolas PERRON over 11 years ago
- Status changed from Discussion to 8
- Assignee changed from Jonathan CLARKE to Nicolas PERRON
- Target version changed from 2.4.7 to 2.6.3
Updated by Nicolas PERRON over 11 years ago
- Target version changed from 2.6.3 to 2.6.4
Updated by Nicolas PERRON about 11 years ago
- Status changed from 8 to Discussion
- Assignee changed from Nicolas PERRON to Matthieu CERDA
I don't know how to deal with that issue:
- There is a "bug" in all versions of this Technique:
bundle edit_line set_arbitrary_file_content(content, enforce) { classes: "preserve_file_content" expression => strcmp("true", "$(enforce)"); insert_lines: preserve_file_content:: "$(content)" insert_type => "preserve_block"; !preserve_file_content:: "$(content)"; }
If the file has to be enforced, it is considered has preserved and then if the content is a block content, it will be preserve. If the file is not enforced, it will be not considered as preserved and then the content will be process for each line....
The use of preserve block will lead to a non convergent promise which will lead itself to a file containing at each run more lines
- If I try to preserve the block content, like said above, the content will be added at each run. Then, a solution could be to remove each line before to add the content we want but this will lead to a non convergent promise and the reporting will always considered as "repaired" instead of "success".
With these informations, I don't know how to do the work. Any idea ?
Updated by Matthieu CERDA about 11 years ago
- Assignee changed from Matthieu CERDA to Nicolas PERRON
I think for block edition, a template would be more adapted, but a template is unusable in this case. We are hitting the limits of what we can do here...
Maybe it would be a job to be done in another technique, a templating one ?
Updated by Nicolas PERRON about 11 years ago
- Target version changed from 2.6.4 to 2.6.5
Updated by Nicolas PERRON about 11 years ago
- Target version changed from 2.6.5 to 2.6.6
Updated by Nicolas PERRON about 11 years ago
- Target version changed from 2.6.6 to 2.6.7
Updated by Nicolas PERRON about 11 years ago
- Target version changed from 2.6.7 to 2.6.8
Updated by Nicolas PERRON about 11 years ago
- Target version changed from 2.6.8 to 2.6.9
Updated by Nicolas PERRON almost 11 years ago
- Target version changed from 2.6.9 to 2.6.10
Updated by Nicolas CHARLES almost 11 years ago
- Status changed from Discussion to 8
- Assignee changed from Nicolas PERRON to Nicolas CHARLES
i'm taking over the ticket
Updated by Nicolas CHARLES almost 11 years ago
Ha. Preserve block is broken in CFEngine
https://cfengine.com/dev/issues/2315
Updated by Nicolas CHARLES almost 11 years ago
after mch tries and tinkering, i cannot get cfengine to manage a block section, with order.
I guess the easier way would be to use a module, that would :
- check if the section is there (by header)
- if it is there, check the content (multiline regexp?)
- if it is invalid, replace it
it could look like that
http://stackoverflow.com/questions/10092328/bash-how-to-check-and-insert-a-string-within-a-block-in-a-file
Updated by Nicolas CHARLES almost 11 years ago
- Category set to Techniques
- Status changed from 8 to Pending technical review
- Assignee changed from Nicolas CHARLES to Jonathan CLARKE
- Target version changed from 2.6.10 to 2.4.13
- Pull Request set to https://github.com/Normation/rudder-techniques/pull/256
Updated by Nicolas CHARLES almost 11 years ago
- Status changed from Pending technical review to Pending release
- % Done changed from 0 to 100
Applied in changeset commit:6761c7297a9dc424bfea8577e5bee681d68bf3c9.
Updated by Nicolas CHARLES almost 11 years ago
- Status changed from Pending release to In progress
Updated by Nicolas CHARLES almost 11 years ago
- Pull Request changed from https://github.com/Normation/rudder-techniques/pull/256 to https://github.com/Normation/rudder-techniques/pull/258
Updated by Nicolas CHARLES almost 11 years ago
- Status changed from In progress to Pending release
Applied in changeset commit:3b3fae6b9a7d7ce422cf156f03598e88a0259e57.
Updated by Vincent MEMBRÉ almost 11 years ago
- Status changed from Pending release to Discussion
bunlde edit_line rudder_ensure_section_content has not been added in stdlib in last pull request, since this issue has not been release, I'm making another one to add it again it
Updated by Vincent MEMBRÉ almost 11 years ago
- Status changed from Discussion to Pending technical review
- Pull Request changed from https://github.com/Normation/rudder-techniques/pull/258 to https://github.com/Normation/rudder-techniques/pull/264
Updated by Vincent MEMBRÉ almost 11 years ago
- Status changed from Pending technical review to Pending release
Applied in changeset commit:eaa87aa59a3d45177c1ccbab3a152d3a12eb5463.
Updated by Nicolas CHARLES almost 11 years ago
Applied in changeset commit:bdafec55df1a897d6b029aae5adefab3cf4ff1bc.
Updated by Vincent MEMBRÉ almost 11 years ago
- Target version changed from 2.4.13 to 2.6.10
Since we will not make any more releases of 2.4 version, moving all those issues to 2.6
Updated by Vincent MEMBRÉ almost 11 years ago
- Subject changed from (ex PT/ Technique) Enforce a file content: This is not possible to add a block content or at a specified location of the file. to It is not possible to add a block content or at a specified location of a file using 'Enfore file content' Technique
Updated by Vincent MEMBRÉ almost 11 years ago
- Subject changed from It is not possible to add a block content or at a specified location of a file using 'Enfore file content' Technique to It is not possible to add a block content or at a specified location of a file using 'Enforce file content' Technique
Updated by Vincent MEMBRÉ almost 11 years ago
- Status changed from Pending release to Released
This bug has been fixed in Rudder 2.6.10 which was released today.
Check out:
- The release announcement: http://www.rudder-project.org/pipermail/rudder-announce/2014-January/000070.html
- The full ChangeLog: http://www.rudder-project.org/foswiki/bin/view/System/Documentation:ChangeLog26
- Download information: https://www.rudder-project.org/site/get-rudder/downloads/
Updated by Benoît PECCATTE over 9 years ago
- Project changed from 24 to Rudder
- Category changed from Techniques to Techniques
Updated by Benoît PECCATTE almost 9 years ago
- Target version changed from 2.6.10 to 2.4.12