# Lineinfile + insertafter

**URL:** <https://forum.ansible.com/t/lineinfile-insertafter/24629>\
**Category:** Ansible Project\
**Created:** [June 2, 2017, 7:32am UTC](https://forum.ansible.com/t/lineinfile-insertafter/24629 "2017-06-02T07:32:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mona\_Gopal](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mona\_Gopal](https://forum.ansible.com/u/Mona_Gopal)\
**Post date:** [June 2, 2017, 7:32am UTC](https://forum.ansible.com/t/lineinfile-insertafter/24629/1 "2017-06-02T07:32:49Z")

</div>

Hello,  
The task is as below:

- name: replace  
lineinfile:  
dest: /tmp/sample/test\_file.txt  
regexp: “#}”  
insertafter: ’ "compute": 2,’  
line: “}”  
state: present

And below is my file content:

#OPENSTACK\_API\_VERSIONS = {

# “data-processing”: 1.1,

# “identity”: 3,

# “image”: 2,

# “volume”: 2,

# “compute”: 2,

**#}**

#PROJECT\_TABLE\_EXTRA\_INFO = {

# ‘phone\_num’: \_(‘Phone Number’),

#}  
#USER\_TABLE\_EXTRA\_INFO = {

# ‘phone\_num’: \_(‘Phone Number’),

#}

**_EXPECTED RESULT:_**

OPENSTACK\_API\_VERSIONS = {

“data-processing”: 1.1,

“identity”: 3,

“image”: 2,

“volume”: 2,

“compute”: 2,

}

#PROJECT\_TABLE\_EXTRA\_INFO = {

# ‘phone\_num’: \_(‘Phone Number’),

#}

#USER\_TABLE\_EXTRA\_INFO = {

# ‘phone\_num’: \_(‘Phone Number’),

#}

**_CURRENT RESULT:_**

OPENSTACK\_API\_VERSIONS = {

“data-processing”: 1.1,

“identity”: 3,

“image”: 2,

“volume”: 2,

“compute”: 2,

#}

#PROJECT\_TABLE\_EXTRA\_INFO = {

# ‘phone\_num’: \_(‘Phone Number’),

#}

#USER\_TABLE\_EXTRA\_INFO = {

# ‘phone\_num’: \_(‘Phone Number’),

}

The line mentioned in insertafter is not recognized. Kindly, suggest a way forward.

Regards,

Mona G

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 2, 2017, 11:10am UTC](https://forum.ansible.com/t/lineinfile-insertafter/24629/2 "2017-06-02T11:10:14Z")

</div>

You should read this thread  
[https://groups.google.com/forum/#!topic/ansible-project/SK3VF7R4aB4](https://groups.google.com/forum/#!topic/ansible-project/SK3VF7R4aB4)
