Ansible Tip: Running Interactive Scripts with Ansible

Sometimes when you run a script with Ansible it requires an interactive prompt like y/n or something similar.
I recently ran into this problem and after a bit of head bashing I found the following solution in a little Linux utility called ‘yes’ which repeatedly outputs a line with a specified STRING(s), or ‘y’. In this case I just needed ‘y’ so I went with the default.
Here is my Ansible Task file with the ‘yes’ command in use:
---
# file: roles/apigee_edge_base/tasks/apigee_install.yml
#
# slight hack below we pipe the "yes" command to send a y to our installer script because it complains about the OS version not being supported!
#
- name: Apigee Install - Run the apigee-install.sh shell script to setup the environment
shell: yes | ./apigee-install.sh -r /opt -d /opt -j /usr/java/default
args:
chdir: "{{ unpack_dir }}/apigee-edge-{{ edge_version }}"
remote_user: root
sudo: yes
If you know a more elegant way to do this then let me know (I thought about ‘echo y |’ as well but liked this one).