wi8yrq
Last Updated: February 25, 2016
·
1.571K
· ramondelafuente
24ef80339ca19df482961c1571cda607

Ansible lineinfile with lookup()

There are a few situations where Ansible's lineinfile module is useful, but complicated because you don't know the exact line that should exist.

You might end up using a template, or a command that registers a variable, but if the line you wish to add is the result of a command on the host you can use the lookup plugin and save yourself a an extra task.

One example is adding a host to the known_hosts file:

lineinfile: dest=/etc/ssh/ssh_known_hosts 
    line="{{lookup('pipe', 'ssh-keyscan github.com') }}" 
    state=present 
    create=yes mode=0644
Say Thanks
Respond

1 Response
Add your response

13789
24ef80339ca19df482961c1571cda607

Heads-up: this is broken in Ansbile 1.5.1 because of the way shell commands are started. Fixed in 1.5.3 and up.

over 1 year ago ·
Filed Under