Value of `changed` after a "search and remplace using `sed`?

It returns changed=True because it had to run the command.

You could precede the task with a “grep” command using “register” and attach a “when” to your task to conditionally decide to not run it, sure, but a even better way would be to just template the sources.list file.

You could try my bash module for sed ‘s’:

https://github.com/ansible-contrib/ansible-plugins/blob/devel/library/seds

(Just wrote it for sports on doing something in bash, didn’t extensively used it)

Or you could use the aptrepo module, which would need lots of invocations in this use case

But templating would be the better option, as Michael said.

Serge

Yes, but the “grep” task will still always return changed=True, whatever the result of grep is? Am I misunderstanding something? My goal is for ansible-playbook to print changed=0 at the end of its execution when nothing has changed.

Then you probably want something like Serge wrote.