ユーザー入力を必要とするシェルスクリプトを以下に示します。
read -e -p "Enter any string:" varible
echo 'Entered value is ::' $varible > abc.txt
複数のサーバーでユーザー入力を必要とするこのスクリプトを実行したかったので、以下の yml を使用して実現しました。
- name: Here we start
hosts: all
tasks: # is a list
- name: Execute the user interactive script
expect:
command: /usr/bin/sh /home/ansible/test.sh
responses:
"Enter any string:": "Success Script Executed"
ただし、以下のコマンドを使用しようとしている場合は、ユーザー入力を促進しません。
ansible all -a 'sh /home/ansible/test.sh'
1)上記のスクリプトのユーザー入力を求める正しい ansible コマンドを共有してください。
2)上記のスクリプトについても、ユーザーに代わってデフォルト値を取る正しい ansible コマンドを共有してください。