# Parentheses in lineinfile line argument

**URL:** <https://forum.ansible.com/t/parentheses-in-lineinfile-line-argument/16040>\
**Category:** Ansible Project\
**Created:** [August 26, 2014, 1:57pm UTC](https://forum.ansible.com/t/parentheses-in-lineinfile-line-argument/16040 "2014-08-26T13:57:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matteo\_Ceccarello](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@Matteo\_Ceccarello](https://forum.ansible.com/u/Matteo_Ceccarello)\
**Post date:** [August 26, 2014, 1:57pm UTC](https://forum.ansible.com/t/parentheses-in-lineinfile-line-argument/16040/1 "2014-08-26T13:57:29Z")

</div>

Hi all!

I’m trying to use the lineinfile module to configure NFS exports and I need to put parentheses in my line argument.

If I do something like this

- name: Export the NFS directory for root  
lineinfile: dest=/etc/exports  
regexp=‘/root/nfs’  
line=‘/root/nfs 192.168.1.0/255.255.255.0(rw,no\_root\_squash,subtree\_check)’

I get a line in my /etc/exports that looks like

‘/root/nfs 192.168.1.0/255.255.255.0(rw,no\_root\_squash,subtree\_check)’

That is, surrounded by quotes. The problem is that this format is invalid, so I have to remove the quotes.  
I made a few tests, and I found out that removing the parentheses works

- name: Test  
lineinfile: dest=/etc/exports  
line=“/root/nfs 192.168.1.0/255.255.255.0”

yields the following line (without quotes)

/root/nfs 192.168.1.0/255.255.255.0

whereas reintroducing the parentheses reintroduces also quotes

- name: Test  
lineinfile: dest=/etc/exports  
line=“/root/nfs 192.168.1.0/255.255.255.0()”

‘/root/nfs 192.168.1.0/255.255.255.0()’

I tried to escape the parentheses and this removes the quotes, but escape chars remain!

- name: Test  
lineinfile: dest=/etc/exports  
line=“/root/nfs 192.168.1.0/255.255.255.0()”

/root/nfs 192.168.1.0/255.255.255.0()

Is this a bug? Am I missing something?

Thank you very much 🙂

Matteo

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 26, 2014, 10:41pm UTC](https://forum.ansible.com/t/parentheses-in-lineinfile-line-argument/16040/2 "2014-08-26T22:41:24Z")

</div>

Lineinfile doesn’t have any particular handling of a parenthesis.

I don’t think I see a bug in the above, but it can be hard to use.

I recommend templates for 99.9999% of all use cases, above lineinfile.

Please do confirm your ansible version if you don’t mind…

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [August 27, 2014, 9:44am UTC](https://forum.ansible.com/t/parentheses-in-lineinfile-line-argument/16040/3 "2014-08-27T09:44:10Z")

</div>

May I suggest the following way of doing it:

`

- name: mounting shares  
mount: name={{ item.name }} src={{ item.src }} fstype=nfs opts={{ item.opts }} state=mounted  
with\_items:
- { name: ‘/root/nfs’, src: ‘hostname:/ExportName’, opts: ‘defaults’ }  
[…]  
tags: nfs

`

The mount module works like a charm and the documentation is really clear on the various states it supports.

---

<div class="post-metadata">

**Author:** ![Matteo\_Ceccarello](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@Matteo\_Ceccarello](https://forum.ansible.com/u/Matteo_Ceccarello)\
**Post date:** [September 2, 2014, 1:33pm UTC](https://forum.ansible.com/t/parentheses-in-lineinfile-line-argument/16040/4 "2014-09-02T13:33:05Z")

</div>

Thank you for the suggestions and sorry for the late reply.

I’ll try the templates module. As for the mount module, as far as I understant it’s to configure /etc/fstab on the client side. I’m trying to configure the server side, i.e. /etc/exports. Anyway, I’ll definetly use the mount module on the clients.

Back to the parentheses problem, the version of Ansible I’m using is 1.7 from the Fedora repositories.

Matteo

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 2, 2014, 10:46pm UTC](https://forum.ansible.com/t/parentheses-in-lineinfile-line-argument/16040/5 "2014-09-02T22:46:11Z")

</div>

If you like, please file a bug on [github.com/ansible/ansible](http://github.com/ansible/ansible) so we can investigate.

---

<div class="post-metadata">

**Author:** ![Vincent\_Hardion](https://avatars.discourse-cdn.com/v4/letter/v/da6949/32.png) [@Vincent\_Hardion](https://forum.ansible.com/u/Vincent_Hardion)\
**Post date:** [September 5, 2014, 8:51pm UTC](https://forum.ansible.com/t/parentheses-in-lineinfile-line-argument/16040/6 "2014-09-05T20:51:27Z")

</div>

Hi,

Me also I need to change the /etc/exports but I can’t use the template as this config file is shared with another system which don’t use ansible 😃

I did some investigation and in fact just “t.t()” is enough to generate the quote (took me some hours to find the good combinaison).

But anyway there is a fix in 1.7.1 ([https://github.com/ansible/ansible/issues/8535](https://github.com/ansible/ansible/issues/8535))

Cheers,  
Vincent

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 5, 2014, 9:17pm UTC](https://forum.ansible.com/t/parentheses-in-lineinfile-line-argument/16040/7 "2014-09-05T21:17:20Z")

</div>

Yep 1.7.1 is already released now, so should be good to go!
