Skip to content

(MODULES-5003) file_line fix all broken lines #788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2017

Conversation

tphoney
Copy link
Contributor

@tphoney tphoney commented Jul 3, 2017

If the following lines exist
hard core 90
hard core 10
it correctly corrects both lines to
hard core 0
hard core 0
However if these lines exist in the file
hard core 90
hard core 0
It incorrectly does nothing
It should correct the first line

@tphoney tphoney requested review from eputnam and neilbinney July 3, 2017 16:10
@tphoney tphoney closed this Jul 3, 2017
@tphoney tphoney reopened this Jul 3, 2017
@tphoney tphoney closed this Jul 5, 2017
@tphoney tphoney reopened this Jul 5, 2017
@eputnam eputnam merged commit 578220e into puppetlabs:master Jul 7, 2017
@tkishel
Copy link
Contributor

tkishel commented Jul 12, 2017

Confirmed:

[root@pe-201722-master production]# cat manifests/site.pp 
node default {
  file_line { 'limits: disable core dumps': 
    ensure   => present, 
    path     => '/etc/security/limits.conf', 
    line     => "*\thard\tcore\t0", 
    match    => "^[ \t]*\*[ \t]+hard[ \t]+core[ \t]+.*", 
    multiple => true, 
  }

  file_line { 'limits: test' :
    path => '/etc/security/limits.conf',
    line => '# test="once"',
  }
}
[root@pe-201722-master production]# cat /etc/security/limits.conf 
*	hard	core	0
*	hard	core	0

[root@pe-201722-master production]# puppet agent -t 
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for pe-201722-master.puppetdebug.vlan
Info: Applying configuration version '1499892694'
Notice: /Stage[main]/Main/Node[default]/File_line[limits: test]/ensure: created
Notice: Applied catalog in 9.37 seconds

[root@pe-201722-master production]# cat /etc/security/limits.conf 
*	hard	core	0
*	hard	core	0
# test="once"

[root@pe-201722-master production]# puppet agent -t 
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for pe-201722-master.puppetdebug.vlan
Info: Applying configuration version '1499892726'
Notice: /Stage[main]/Main/Node[default]/File_line[limits: disable core dumps]/ensure: created
Notice: /Stage[main]/Main/Node[default]/File_line[limits: test]/ensure: created
Notice: Applied catalog in 9.69 seconds

[root@pe-201722-master production]# cat /etc/security/limits.conf 
*	hard	core	0
*	hard	core	0
# test="once"
# test="once"

[root@pe-201722-master production]# puppet agent -t 
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for pe-201722-master.puppetdebug.vlan
Info: Applying configuration version '1499892770'
Notice: /Stage[main]/Main/Node[default]/File_line[limits: disable core dumps]/ensure: created
Notice: /Stage[main]/Main/Node[default]/File_line[limits: test]/ensure: created
Notice: Applied catalog in 9.16 seconds

[root@pe-201722-master production]# cat /etc/security/limits.conf 
*	hard	core	0
*	hard	core	0
# test="once"
# test="once"
# test="once"

hunner added a commit to hunner/puppetlabs-stdlib that referenced this pull request Oct 12, 2017
https://tickets.puppetlabs.com/browse/MODULES-5003 gave rise to
puppetlabs#788 which caused
different behavior based on whether the line value was matched by the
match regex.

This resolves the behavior by adding a new parameter to control whether
multiple matches should universally be replaced by the line value, or
whether matches should be left alone when the line exists elsewhere in
the file.

This problem only affects modifying multiple lines when the line already
exists.
hunner added a commit to hunner/puppetlabs-stdlib that referenced this pull request Oct 13, 2017
https://tickets.puppetlabs.com/browse/MODULES-5003 gave rise to
puppetlabs#788 and
puppetlabs#794 which caused
different behavior based on whether the line value was matched by the
match regex or not.

This resolves the behavior by adding a new parameter to control whether
multiple matches should universally be replaced by the line value, or
whether matches should be left alone when the line exists elsewhere in
the file.

This problem only affects modifying multiple lines when the line already
exists.

I also revised many of the tests and some of the documentation where
wrong or ambiguous.
hunner added a commit to hunner/puppetlabs-stdlib that referenced this pull request Oct 13, 2017
https://tickets.puppetlabs.com/browse/MODULES-5003 gave rise to
puppetlabs#788 and
puppetlabs#794 which caused
different behavior based on whether the line value was matched by the
match regex or not.

This resolves the behavior by adding a new parameter to control whether
multiple matches should universally be replaced by the line value, or
whether matches should be left alone when the line exists elsewhere in
the file.

This problem only affects modifying multiple lines when the line already
exists.

I also revised many of the tests and some of the documentation where
wrong or ambiguous.
hunner added a commit to hunner/puppetlabs-stdlib that referenced this pull request Oct 16, 2017
https://tickets.puppetlabs.com/browse/MODULES-5003 gave rise to
puppetlabs#788 and
puppetlabs#794 which caused
different behavior based on whether the line value was matched by the
match regex or not.

The change in behavior was both breaking and broken, though that was
hard to tell because the behavior was ill-described in general.

[bugfix] This commit resolves the breaking behavior by reverting the
behavior of "replacing matches when a line matching `line` exists even
when `multiple` is set to `true`".

[feature] This commit adds a new parameter to make file_line replace all
matches universally with the `line` value, even when the line exists
elsewhere in the file. This feature only affects modifying multiple
lines in a file when the `line` value already exists.

[bugfix] This commit more strictly defines the various interactions of
`ensure`, `match`, `append_on_no_match`, `replace`, `multiple`, and
`replace_all_matches_not_matching_line`. It also more clearly documents
and tests these interactions.
cegeka-jenkins pushed a commit to cegeka/puppet-stdlib that referenced this pull request Jul 17, 2019
https://tickets.puppetlabs.com/browse/MODULES-5003 gave rise to
puppetlabs/puppetlabs-stdlib#788 and
puppetlabs/puppetlabs-stdlib#794 which caused
different behavior based on whether the line value was matched by the
match regex or not.

The change in behavior was both breaking and broken, though that was
hard to tell because the behavior was ill-described in general.

[bugfix] This commit resolves the breaking behavior by reverting the
behavior of "replacing matches when a line matching `line` exists even
when `multiple` is set to `true`".

[feature] This commit adds a new parameter to make file_line replace all
matches universally with the `line` value, even when the line exists
elsewhere in the file. This feature only affects modifying multiple
lines in a file when the `line` value already exists.

[bugfix] This commit more strictly defines the various interactions of
`ensure`, `match`, `append_on_no_match`, `replace`, `multiple`, and
`replace_all_matches_not_matching_line`. It also more clearly documents
and tests these interactions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants