Parentheses in lineinfile line argument

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 :slight_smile:

Matteo

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…

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.

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

If you like, please file a bug on github.com/ansible/ansible so we can investigate.

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 :smiley:

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)

Cheers,
Vincent

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