Implement diff mode in lineinfile
This commit is contained in:
parent
29229d0641
commit
b26403a90b
2 changed files with 13 additions and 14 deletions
|
@ -253,6 +253,7 @@ function Ansible:parse(inputfile)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.internal_params = extract_internal_ansible_params(params)
|
self.internal_params = extract_internal_ansible_params(params)
|
||||||
|
self._diff = self.internal_params['_ansible_diff']
|
||||||
|
|
||||||
-- resolve aliases
|
-- resolve aliases
|
||||||
params, err = canonicalize(params, self.spec)
|
params, err = canonicalize(params, self.spec)
|
||||||
|
|
|
@ -83,10 +83,9 @@ function present(module, dest, regexp, line, insertafter, insertbefore, create,
|
||||||
lines = splitlines(module:slurp(dest))
|
lines = splitlines(module:slurp(dest))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- No diff mode on memory restrained devices...
|
if module._diff then
|
||||||
-- if module:_diff then
|
diff['before'] = join(lines, "\n")
|
||||||
-- diff['before'] = -- ''.join(lines
|
end
|
||||||
-- end
|
|
||||||
|
|
||||||
local mre = regexp
|
local mre = regexp
|
||||||
|
|
||||||
|
@ -170,10 +169,9 @@ function present(module, dest, regexp, line, insertafter, insertbefore, create,
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- No diff mode on memory restrained devices...
|
if module._diff then
|
||||||
-- if module:_diff then
|
diff['after'] = join(lines, "\n")
|
||||||
-- diff['after'] = -- ''.join(lines)
|
end
|
||||||
-- end
|
|
||||||
|
|
||||||
local backupdest = ""
|
local backupdest = ""
|
||||||
if changed and not module:check_mode() then
|
if changed and not module:check_mode() then
|
||||||
|
@ -207,9 +205,9 @@ function absent(module, dest, regexp, line, backup)
|
||||||
|
|
||||||
local lines = splitlines(module:slurp(dest))
|
local lines = splitlines(module:slurp(dest))
|
||||||
|
|
||||||
-- if module:_diff then
|
if module._diff then
|
||||||
-- diff['before'] = join(lines, "\n")
|
diff['before'] = join(lines, "\n")
|
||||||
-- end
|
end
|
||||||
|
|
||||||
local cre
|
local cre
|
||||||
if regexp ~= nil then
|
if regexp ~= nil then
|
||||||
|
@ -234,9 +232,9 @@ function absent(module, dest, regexp, line, backup)
|
||||||
lines = filter(matcher, lines)
|
lines = filter(matcher, lines)
|
||||||
changed = #found > 0
|
changed = #found > 0
|
||||||
|
|
||||||
-- if module:_diff then
|
if module._diff then
|
||||||
-- diff['after'] = join(lines, "\n")
|
diff['after'] = join(lines, "\n")
|
||||||
-- end
|
end
|
||||||
|
|
||||||
backupdest = ""
|
backupdest = ""
|
||||||
if changed and not module:check_mode() then
|
if changed and not module:check_mode() then
|
||||||
|
|
Loading…
Add table
Reference in a new issue