Maybe http://docs.ansible.com/ansible/lineinfile_module.html will help?

[wani@linux tmp ]$ cat /tmp/a
<value1> <text1>
<value2> <text2>
<value3> <text1>
[wani@linux tmp ]$ cat a.yaml
- hosts: localhost

  tasks:
    - lineinfile:
        path: /tmp/a
        regexp: "^<value1> <text1>"
        state: absent

    - lineinfile:
        path: /tmp/a
        regexp: "^<value3> <text1>"
        line: "<valuex> <text1>"
[wani@linux tmp ]$ ansible-playbook a.yaml
 [WARNING]: Host file not found: /etc/ansible/hosts

 [WARNING]: provided hosts list is empty, only localhost is available


PLAY [localhost]
****************************************************************************************************************************************************************************

TASK [Gathering Facts]
**********************************************************************************************************************************************************************
ok: [localhost]

TASK [lineinfile]
***************************************************************************************************************************************************************************
changed: [localhost]

TASK [lineinfile]
***************************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP
**********************************************************************************************************************************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0


[wani@linux tmp ]$ cat /tmp/a
<value2> <text2>
<valuex> <text1>


On Thu, Feb 16, 2017 at 9:32 AM, Suresh Grandhi <[email protected]> wrote:

> I am looking to replace or delete redundant lines in a file at different
> line numbers.
>
> For example, a file has the following content
>
> <value1> <text1>
> <value2> <text2>
> <value3> <text1>
>
> In this case, I want to remove <value1> <text1>  and replace <value3>
> <text1> with <valuex> <text1>.
> Is there a possibility to do this in Ansible?
>
> --
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/ansible-project/76f8b842-eed8-4785-bd12-227655ecb300%40googlegroups.
> com
> <https://groups.google.com/d/msgid/ansible-project/76f8b842-eed8-4785-bd12-227655ecb300%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Nehal J Wani

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAG6NSrn%2B-X0EqxuFLaGZuG4qbOOA7JEZcG5jHMLSQeOxK3OgBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to