From 39a8638ec0b2193f97e1ede5f4ab4139b357278c Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Wed, 15 Feb 2017 15:52:31 +0100 Subject: [PATCH] Advanced example using shell with other executable (#21462) The shell module is quite versatile in its use. --- lib/ansible/modules/commands/shell.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/ansible/modules/commands/shell.py b/lib/ansible/modules/commands/shell.py index c2f8daa69c..2877207327 100644 --- a/lib/ansible/modules/commands/shell.py +++ b/lib/ansible/modules/commands/shell.py @@ -104,6 +104,26 @@ EXAMPLES = ''' - name: Run a command using a templated variable (always use quote filter to avoid injection) shell: cat {{ myfile|quote }} + +# You can use shell to run other executables to perform actions inline +- name: Run expect to wait for a successful PXE boot via out-of-band CIMC + shell: | + set timeout 300 + spawn ssh admin@{{ cimc_host }} + + expect "password:" + send "{{ cimc_password }}\n" + + expect "\n{{ cimc_name }}" + send "connect host\n" + + expect "pxeboot.n12" + send "\n" + + exit 0 + args: + executable: /usr/bin/expect + delegate_to: localhost ''' RETURN = '''