mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Win lineinfile fix (#35100)
* win_lineinfile: fix #33858. Removed conversion from \r\n * win_lineinfile: added test for #33858 * win_lineinfile: added documentation and more tests for change * win_lineinfile: fixed wrong hash in testing
This commit is contained in:
parent
c2feab0606
commit
e15a903bdf
4 changed files with 72 additions and 27 deletions
|
@ -1,25 +1,9 @@
|
|||
#!powershell
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# WANT_JSON
|
||||
# POWERSHELL_COMMON
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
#Requires -Module Ansible.ModuleUtils.Legacy
|
||||
|
||||
# Write lines to a file using the specified line separator and encoding,
|
||||
# performing validation if a validation command was specified.
|
||||
function WriteLines($outlines, $path, $linesep, $encodingobj, $validate, $check_mode) {
|
||||
Try {
|
||||
$temppath = [System.IO.Path]::GetTempFileName();
|
||||
|
@ -342,15 +326,6 @@ If ($newline -eq "unix") {
|
|||
$linesep = "`n";
|
||||
}
|
||||
|
||||
# Fix any CR/LF literals in the line argument. PS will not recognize either backslash
|
||||
# or backtick literals in the incoming string argument without this bit of black magic.
|
||||
If ($line) {
|
||||
$line = $line.Replace("\r", "`r");
|
||||
$line = $line.Replace("\n", "`n");
|
||||
$line = $line.Replace("``r", "`r");
|
||||
$line = $line.Replace("``n", "`n");
|
||||
}
|
||||
|
||||
# Figure out the proper encoding to use for reading / writing the target file.
|
||||
|
||||
# The default encoding is UTF-8 without BOM
|
||||
|
|
|
@ -39,6 +39,8 @@ options:
|
|||
description:
|
||||
- Required for C(state=present). The line to insert/replace into the file. If C(backrefs) is set, may contain backreferences that will get
|
||||
expanded with the C(regexp) capture groups if the regexp matches.
|
||||
- Be aware that the line is processed first on the controller and thus is dependent on yaml quoting rules. Any double quoted line
|
||||
will have control characters, such as '\r\n', expanded. To print such characters literally, use single or no quotes.
|
||||
backrefs:
|
||||
description:
|
||||
- Used with C(state=present). If set, line can contain backreferences (both positional and named) that will get populated if the C(regexp)
|
||||
|
@ -95,6 +97,11 @@ notes:
|
|||
|
||||
EXAMPLES = r'''
|
||||
# Before 2.3, option 'dest', 'destfile' or 'name' was used instead of 'path'
|
||||
- name: insert path without converting \r\n
|
||||
win_lineinfile:
|
||||
path: c:\file.txt
|
||||
line: c:\return\new
|
||||
|
||||
- win_lineinfile:
|
||||
path: C:\Temp\example.conf
|
||||
regexp: '^name='
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue