0

Is is possible to use expect script from Vagrantfile for provisioning?

It looks like file inside the installOracle.exp script is not there at the proper moment (see error log):

spawn "/var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh"

File is there!:)

[vagrant@wemdbc01 ~]$ ls -la /var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh
-rwxrwxrwx. 1 vagrant vagrant 541 May 25 08:43 /var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh

Related part of my Vagrantfile:

  [...]
  db.vm.synced_folder ".", "/vagrant", disabled: true
  db.vm.synced_folder "C:/Installers", "/var/wminst"
  db.vm.provision :shell, :inline  => "yum -y install expect"
  db.vm.provision :shell, :inline => "expect /var/wminst/vm_provision/oracle_installer/installOracle.exp" 
end

installOracle.exp:

#!/usr/bin/env expect

set timeout 20

spawn "/var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh"

expect "replace Disk1/upgrade/gen_inst.sql?" { send "N\r" }
expect "Specify the HTTP port that will be used for Oracle Application Express" { send "\r" }
expect "Specify a port that will be used for the database listener" { send "\r" }
expect "initial configuration:" { send "root\r" }
expect "Confirm the password:" { send "root\r" }
expect "Do you want Oracle Database 11g Express Edition to be started on boot" { send "y\r" }
expect eof
expect eof
expect "Installation completed successfully." { send "\r" }
expect eof

Error:

==> wemdbc01: Running provisioner: shell...
    wemdbc01: Running: inline script
==> wemdbc01: spawn /var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh
==> wemdbc01: couldn't execute "/var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh": no such file or directory
==> wemdbc01:     while executing
==> wemdbc01: "spawn "/var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh""
==> wemdbc01:     (file "/var/wminst/vm_provision/oracle_installer/installOracle.exp" line 5)
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

Edit 1: Changed:

#!/bin/bash

to

#!/usr/bin/env bash

Error log now:

==> wemdbc01: Running provisioner: shell...
    wemdbc01: Running: inline script
==> wemdbc01: spawn /var/wminst/vm_provision/oracle_installer/installOracleDatabase.sh
: No such file or directory bash
==> wemdbc01: expect: spawn id exp5 not open
==> wemdbc01:     while executing
==> wemdbc01: "expect "Specify the HTTP port that will be used for Oracle Application Express" { send "\r" }"
==> wemdbc01:     (file "/var/wminst/vm_provision/oracle_installer/installOracle.exp" line 8)
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
  • Does the script specify a valid interpreter on the first line with #!? – Kusalananda May 25 '17 at 13:28
  • Good suggestion. Another error now. – Paweł Banach May 25 '17 at 13:45
  • Hmm... It looks like you don't have bash installed, or it is installed in an unusual location which is not in your $PATH. Is the script really a bash script? If not, try #!/bin/sh. – Kusalananda May 25 '17 at 13:47
  • I'm on Windows - does it matter? When connected in to the VM and run scripts manually - they are running just fine. – Paweł Banach May 25 '17 at 13:53
  • The fact that the VM is running on Windows should not matter. I currently unsure as to why it won't work for you, especially as you say that it works well if you run the script manually. There is something about running it with Vagrant that modifies something that I do not understand. – Kusalananda May 25 '17 at 14:02
1

The problematic script was produced on Windows, which meant that it had DOS newlines. This caused the script to fail executing on the Unix VM.

The fact that the VM is running on Windows is not an issue though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.