Using a file as input for lineinfule module

17 views
Skip to first unread message

Felix Gläske

unread,
Jun 5, 2014, 6:37:11 AM6/5/14
to ansible...@googlegroups.com
Hey,
is there a way to use a file from the machine where I run ansible to use as input for the module lineinfile?

Dick Davies

unread,
Jun 5, 2014, 11:19:01 AM6/5/14
to ansible list
I'm assuming you know about templates :)

Can you give an example of the sort of thing you're trying to do?
> --
> 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/0c8048b8-7de3-4967-9a54-8d492a8faf83%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

James Cammarata

unread,
Jun 5, 2014, 11:41:48 AM6/5/14
to ansible...@googlegroups.com
You could use the file lookup to read in the contents of the file you wish, for instance:

{{ lookup('file', '/path/to/file/you/want') }}

Though as Dick mentioned above, it is almost always better to use templates when possible.



Adam Morris

unread,
Jun 5, 2014, 4:21:29 PM6/5/14
to ansible...@googlegroups.com


On Thursday, June 5, 2014 3:37:11 AM UTC-7, Felix Gläske wrote:
Hey,
is there a way to use a file from the machine where I run ansible to use as input for the module lineinfile?

I'm not sure what you mean here?  Are you wanting to create a file on the destination machine based on one on the source machine with changes?  If so then templates are what you want (and the file module rather than lineinfile)

If you want to provide multiple patterns/changes to lineinfile then you either want to use templates and assemble or lineinfile and with_items...

If it's something else perhaps you should tell us your use case rather than ask how to do something.. Perhaps people have an entirely different way to do what you want...

Adam
Reply all
Reply to author
Forward
0 new messages