Parentheses in lineinfile line argument

246 views
Skip to first unread message

Matteo Ceccarello

unread,
Aug 26, 2014, 9:57:30 AM8/26/14
to ansible...@googlegroups.com
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

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)

whereas reintroducing the parentheses reintroduces also quotes

- name: Test
  lineinfile: dest=/etc/exports
              line="/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

Michael DeHaan

unread,
Aug 26, 2014, 6:41:27 PM8/26/14
to ansible...@googlegroups.com
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...




Matteo

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8ef3b2c5-de9f-4930-bdc7-69d20f6170ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Vaida

unread,
Aug 27, 2014, 5:44:10 AM8/27/14
to ansible...@googlegroups.com
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.

Matteo Ceccarello

unread,
Sep 2, 2014, 9:33:05 AM9/2/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Sep 2, 2014, 6:46:14 PM9/2/14
to ansible...@googlegroups.com
If you like, please file a bug on github.com/ansible/ansible so we can investigate.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Vincent Hardion

unread,
Sep 5, 2014, 4:51:27 PM9/5/14
to ansible...@googlegroups.com
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 :-D
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

Michael DeHaan

unread,
Sep 5, 2014, 5:17:24 PM9/5/14
to ansible...@googlegroups.com
Yep 1.7.1 is already released now, so should be good to go!




Reply all
Reply to author
Forward
0 new messages