lineinfile when two lines are the same

44 views
Skip to first unread message

Vince Skahan

unread,
Mar 29, 2015, 12:34:20 AM3/29/15
to ansible...@googlegroups.com
I'm installing a piece of software that requires me to edit a user=xyz line into a monolithic config file that is .ini like in format.

[function-x]
# user=myuserhere
 
[function-y]
# other stuff here
# more stuff here
 
[function-z]
# user=myuserhere


So suppose I have a config that requires me to uncomment the line in [function-Z] and substitute in the right value for the username.

How do you specify which of the two identical lines in the file that you want to edit ?
Any suggestions ?




Dan Vaida

unread,
Mar 29, 2015, 3:33:40 PM3/29/15
to ansible...@googlegroups.com
Would it be acceptable to template that config file? Perhaps save that chunk only, in a templated file that would be later on included.

Adam Herzog

unread,
Mar 29, 2015, 3:57:26 PM3/29/15
to ansible...@googlegroups.com
Try the ini_file module (http://docs.ansible.com/ini_file_module.html) instead of lineinfile.

You want something like this, I think:

- ini_file:
dest=/etc/anotherconf
section=function-z
option=user
value=myuserhere
backup=yes


-A

--
Adam Herzog
ad...@adamherzog.com
Reply all
Reply to author
Forward
0 new messages