Help with lineinfile and backrefs (v1.1)

1,830 views
Skip to first unread message

Ian Dexter Marquez

unread,
May 16, 2013, 9:31:55 PM5/16/13
to ansible...@googlegroups.com
Hi,

I can't seem to make this work from the command line:

ansible -m lineinfile -a "dest=/etc/ssh/sshd_config backup=yes backrefs=yes regexp='^(AllowGroups .*)$' line='\\1 groupname'" -vvv -s -K local

which replaces the whole "AllowGroups .*" line with " wheel". 

The playbook entry works fine, though:

lineinfile dest=/etc/ssh/sshd_config backup=yes backrefs=yes regexp="^(AllowGroups .*)$" line="\\1 $groupname"


I'm most likely escaping it wrong? Any pointers will be greatly appreciated. Thanks.

- Ian

Michael DeHaan

unread,
May 17, 2013, 2:01:35 PM5/17/13
to ansible...@googlegroups.com
I'm only skimming this, but 

.* 

is a greedy expression so you will want to terminate it with something?

I'm also not sure what you think "$groupname" is but it's not something Ansible gives you.






--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Andreas Piesk

unread,
May 17, 2013, 2:29:13 PM5/17/13
to ansible...@googlegroups.com, Ian Dexter Marquez
On 17.05.2013 03:31, Ian Dexter Marquez wrote:
>
> I can't seem to make this work from the command line:
>
> ansible -m lineinfile -a "dest=/etc/ssh/sshd_config backup=yes
> backrefs=yes regexp='^(AllowGroups .*)$' line='\\1 groupname'" -vvv
> -s -K local

switch the quotes. quote the argument string with single quotes to keep
the shell from messing with it:

ansible -m lineinfile -a 'dest=/etc/ssh/sshd_config backup=yes
backrefs=yes regexp="^(AllowGroups .*)$" line="\\1 $groupname"' -vvv -s
-K local


regards,
-ap

Philippe Eveque

unread,
May 18, 2013, 12:04:37 PM5/18/13
to ansible...@googlegroups.com
And this is not idempotent as it append the contents of the $groupname to the AllowGroups declaration
Not necessarely what you want
 
Phil


2013/5/17 Andreas Piesk <a.p...@gmx.net>
--
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-project+unsubscribe@googlegroups.com.

Ian Dexter R. Marquez

unread,
May 22, 2013, 9:47:11 PM5/22/13
to Andreas Piesk, ansible...@googlegroups.com
On Sat, May 18, 2013 at 2:29 AM, Andreas Piesk <a.p...@gmx.net> wrote:

> switch the quotes. quote the argument string with single quotes to keep the
> shell from messing with it:
>
> ansible -m lineinfile -a 'dest=/etc/ssh/sshd_config backup=yes backrefs=yes
> regexp="^(AllowGroups .*)$" line="\\1 $groupname"' -vvv -s -K local
>
>
> regards,
> -ap

It worked! Thanks.

Admittedly, this is an off-band change to the standard sshd_config
file -- necessary for those one-off tasks to provide temporary SSH
access to certain groups. ("$groupname" is just a placeholder I used;
it will be replaced by the actual group name when invoked. Sorry for
the misunderstanding.)

Thanks again, all!

--
Ian Dexter R. Marquez
http://iandexter.com
Reply all
Reply to author
Forward
0 new messages