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

**URL:** <https://forum.ansible.com/t/value-of-changed-after-a-search-and-remplace-using-sed/12817>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [May 17, 2013, 1:07pm UTC](https://forum.ansible.com/t/value-of-changed-after-a-search-and-remplace-using-sed/12817 "2013-05-17T13:07:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 17, 2013, 1:07pm UTC](https://forum.ansible.com/t/value-of-changed-after-a-search-and-remplace-using-sed/12817/1 "2013-05-17T13:07:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 17, 2013, 1:25pm UTC](https://forum.ansible.com/t/value-of-changed-after-a-search-and-remplace-using-sed/12817/2 "2013-05-17T13:25:38Z")

</div>

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

[https://github.com/ansible-contrib/ansible-plugins/blob/devel/library/seds](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

---

<div class="post-metadata">

**Author:** ![Nicolas\_Grilly](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@Nicolas\_Grilly](https://forum.ansible.com/u/Nicolas_Grilly)\
**Post date:** [May 17, 2013, 2:49pm UTC](https://forum.ansible.com/t/value-of-changed-after-a-search-and-remplace-using-sed/12817/3 "2013-05-17T14:49:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 17, 2013, 5:51pm UTC](https://forum.ansible.com/t/value-of-changed-after-a-search-and-remplace-using-sed/12817/4 "2013-05-17T17:51:11Z")

</div>

Then you probably want something like Serge wrote.
