That will work - yes.  I was so focused on using lineinfile or another
ansible module, I forgot about sed.  Thank you!

On Thu, Jul 27, 2023 at 10:09 AM dulhaver via Ansible Project <
[email protected]> wrote:

> would this do what you want?
>
>
>     - name: edit a line in a file
>       ansible.builtin.command:
>         chdir: /home/username/
>         cmd: 'sed -i "s/This is a file/This is a new file/" somefile'
>
>
>
> On 07/27/2023 3:13 PM CEST Kathy L <[email protected]> wrote:
>
>
> I am trying to edit a string in a multi-line file.  For instance, if I had
> this string:
>
> This is a file and I am editing it
>
> I want to add the string "new" in front of file *if* it does not exist
> already.
>
> I've tried lineinfile, but the issue is that I don't know what else is on
> the line.  There could be more data after "This is a file and I am editing
> it" that I don't want to change.  What is the best way to do this?
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/yZgBhYf9B7Q/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/910865649.311112.1690466922457%40office.mailbox.org
> <https://groups.google.com/d/msgid/ansible-project/910865649.311112.1690466922457%40office.mailbox.org?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAK9%2BsMfzcVAd8MwtvOhmL30UjqsMWtmv5gZujVm%2BVzk%2BqX%3Df0w%40mail.gmail.com.

Reply via email to