Hi ,
I have a file :
cat test.txt
Baseline: ABC ABC1 ABC23 ABC24 +ABC33 ABC_PAD +ABC_PAD_CAD
Now i want to add +TEST_ABC at the end of Line :
Desired O/P :
Baseline: ABC ABC1 ABC23 ABC24 +ABC33 ABC_PAD +ABC_PAD_CAD +TEST_ABC
I am using lineinfile module but the string is getting added after the line
Desired O/P :
Baseline: ABC ABC1 ABC23 ABC24 +ABC33 ABC_PAD +ABC_PAD_CAD +TEST_ABC
Actual O/P:
Desired O/P :
Baseline: ABC ABC1 ABC23 ABC24 +ABC33 ABC_PAD +ABC_PAD_CAD
+TEST_ABC
Below is the task
---
- hosts: localhost
vars:
file_location: /home/raka/test.txt
gather_facts: False
tasks:
- name: Update file
lineinfile:
path: "{{ file_location }}"
state: present
backup: yes
insertafter: '(\s+Baseline: .*)(/>)$'
line: "{{ add_name }}"
Now on executing the playbook as
ansible-playbook file-update.yml -e "add_name=+TEST_ABC"