Comments (4)
I'll probably add something to allow folks to avoid your initial situation. Repeated inserts is a really nasty thing to have happen.
from line.
HI mrswadge,
The sample filters are intended to be idempotent. They are designed to do what you want to tell them to do. They should not insert a line multiple times. Do you have an example of using filter_lines that inserts lines over and over again?
Thinking about it, this might be the case you have a problem with.
In your example above if the newline you insert matches the regex in match then every time the resource runs lines will be inserted. Both after the original match and after the newline match. I can make that experience safer by disallowing that case. The replace filter (not yet published) won't let you insert lines that would be replaced for instance.
Thanks,
Mark
from line.
Hi Mark,
I've worked out what my issue was now and I believe that it is working as intended. My action was modifying a java.security file, specifically the area below.
#
# Default login configuration file
#
#login.config.url.1=file:${user.home}/.java.login.config
I was using the following code
def to_regexp(value, flags=Regexp::IGNORECASE)
return (value.instance_of? Regexp) ? value : Regexp.new("#{Regexp.escape(value)}", flags)
end
match = to_regexp('login.config.url.1')
newline = 'login.config.url.1=file:${java.home}/lib/security/Application.login.config'
filter_lines "modify #{path}/java.security" do
path "#{path}/java.security"
filters after: [match, newline, :last]
end
First time it correctly inserted the line:
#
# Default login configuration file
#
#login.config.url.1=file:${user.home}/.java.login.config
login.config.url.1=file:${java.home}/lib/security/Application.login.config
Each subsequent time it added a new line.
#
# Default login configuration file
#
#login.config.url.1=file:${user.home}/.java.login.config
login.config.url.1=file:${java.home}/lib/security/Application.login.config
login.config.url.1=file:${java.home}/lib/security/Application.login.config
To stop this, I have now changed my match to the following and this is now idempotent.
match = to_regexp('#login.config.url.1')
I will close off this issue.
Cheers,
Stuart
from line.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from line.
Related Issues (20)
- Add an rspec test for sensitive_default helper HOT 1
- Remove the chef 12 support code to make maintenance simpler HOT 5
- Change the name of the dangerfile test case file. HOT 1
- The TESTING.md doc is out of date. HOT 1
- Dangerfile should use failure instead of fail HOT 1
- Remove .rubocop.yml with Dangerfile HOT 1
- Update Changelog HOT 1
- Run latest cookstyle HOT 1
- Update builds to be parallel HOT 1
- Version 2.9.0 is tagged incorrectly HOT 4
- Resource add_to_list needs `provides :add_to_list` in addition to `resource_name :add_to_list` declaration HOT 1
- add_to_list[missing_file fail] on kitchen converge HOT 3
- line Chef 17 compatability
- Undeffine method replace_only HOT 12
- Unit testing line resources using Chefspec HOT 4
- filter_lines does not detect existing lines if / is in stanza. HOT 5
- undefined method `unified_mode'
- Dependency Dashboard
- How does it deal with atomic updates on /etc/hosts file? HOT 8
- Add option to specifiy `manage_symlink_source` for the underlying file resource
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from line.