I am looking to replace or delete redundant lines in a file at different line numbers.
For example, a file has the following content
In this case, I want to remove and replace with .
Is there a possibility to do this in Ansible?
I am looking to replace or delete redundant lines in a file at different line numbers.
For example, a file has the following content
In this case, I want to remove and replace with .
Is there a possibility to do this in Ansible?
Maybe http://docs.ansible.com/ansible/lineinfile_module.html will help?
[wani@linux tmp ]$ cat /tmp/a
[wani@linux tmp ]$ cat a.yaml
tasks:
lineinfile:
path: /tmp/a
regexp: “^ ”
state: absent
lineinfile:
path: /tmp/a
regexp: “^ ”
line: “ ”
[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