Here documents in Ansible

Here documents in Ansible

Sometimes you have a binary which insists on asking you questions when installing it. I ran into that with the linux Crashplan installer.

Of course there is a solution to this, called ‘here documents’. This allows you to issue commands to a script or program by piping in a piece of pre formatted text. Usually the CR/enter/return is represented as a just that. Create the here document with enters at the appropriate places.

With an ansible script that is not possible. Luckily you can use \n in these cases:

ansible hostname -i ~/ansible_hosts -m shell -a "/some_path/install.sh <<EOF\nanswer to question 1\nanswer to question 2\nEOF"

Not that there are 3 \n’s. You need an additional one after the first EOF.

comments powered by Disqus