I have an Ansible playbook which is supposed to replace some characters using stream editor.
sed -i "s+foo+$(<replace_file)+g" some_file
or
sed -i "s/foo/$(<replace_file)/g" some_file
cat some_file
line one: foo
cat replace_file
bar
expected result
line one: bar
actual result
line one: $(<bar)
I have tried the command directly on Ubuntu distro and it works perfectly, but running the command through Ansible gives the error.
2
Answers
The redirection syntax you are trying to use is a Bash feature; if you are running the script using
sh
, it will not work (though I would expect a syntax error rather than what you say in your question that you are getting; it is probably no longer correct after you changed the quotes). See also Difference betweensh
andbash
.Your approach seems extremely brittle, but
should work portably in any POSIX shell.
Another solution would be to actually use bash as the executable: