Added replace module, for multiple regexp match + replace against entire file's contents#4889
Merged
jimi-c merged 1 commit intoansible:develfrom Mar 25, 2014
EvanK:devel
Merged
Added replace module, for multiple regexp match + replace against entire file's contents#4889jimi-c merged 1 commit intoansible:develfrom EvanK:devel
jimi-c merged 1 commit intoansible:develfrom
EvanK:devel
Conversation
EvanK
pushed a commit
to evolution/genesis-wordpress
that referenced
this pull request
Nov 13, 2013
…manual overrides as global vars * if no manual override, calculating php memory_limit via `shell` task * replacing apache default prefork config with include to separate file * generating prefork.conf from template (incl calculated directive values) * using custom `replace` module, see ansible/ansible#4889 Fixes #56
EvanK
pushed a commit
to evolution/genesis-wordpress
that referenced
this pull request
Nov 13, 2013
Both modules should be (hopefully) in ansible's 1.4 release, until then providing them here as custom lib modules: * hostname module, see ansible/ansible#3940 * replace module, see ansible/ansible#4889
Contributor
There was a problem hiding this comment.
might want to mention here that it defaults to using a multiline search
EvanK
pushed a commit
to evolution/genesis-wordpress
that referenced
this pull request
Nov 13, 2013
Both modules should be (hopefully) in ansible's 1.4 release, until then providing them here as custom lib modules: * hostname module, see ansible/ansible#3940 * replace module, see ansible/ansible#4889
Contributor
|
Can you please resubmit this as a single commit so it is easier to review? Thanks! |
Heavily based on existing lineinfile module, but where it literally tests a regexp against *each individual line* of a file, this replace module is more analogous to common uses of a `sed` or `perl` match + replacement of all instances of a pattern anywhere in the file. Was debating adding `all` boolean or `count` numeric options to control how many replacements to make in the destfile (vs currently replacing all instances) Noted use of MULTILINE mode in docs, per suggestion from @jarv
Contributor
Author
|
Okay, squashed down to e88ab43 |
Contributor
|
+1 |
1 similar comment
|
+1 |
Member
|
Merged, thanks! |
jimi-c
pushed a commit
that referenced
this pull request
Dec 6, 2016
Run the same tests as used on Travis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements a multiline regexp replacement against the entire contents of a file. Unlike the
lineinfilemodule, this would allow 1) matching more than one line of said file and 2) replacing multiple matches. Currently, someone would have to implement this with ashelltask using sed or perl.The specific use case I built this for was to replace the entire
mpm_preforksection from ubuntu's default apache config, while leaving the rest of the file in tact; this removes the section in question and replaces it with an include (to a file that I then created from a template):I was also considering adding an
allboolean orcountnumeric parameter to control how many replacements to perform against the file -- it's currently just replacing all matches.