Search code examples
installationchef-infraubuntu-16.04dropboxrecipe

Chef Recipe - interactive responses for DropBox install on Ubuntu


i'm new to chef and trying to learn how to provide answers to installation scripts via the CLI. I'm not having much luck and would appreciate some help?

  bash 'DropboxInstall' do 
  user 'root'
  cwd  '/opt/dropbox'
  code <<-EOH
       dropbox start -i
       expect "Starting Dropbox...\rDropbox is the easiest way to share and store your files online. Want to learn more? Head to https://www.dropbox.com/\rIn order to use Dropbox, you must download the proprietary daemon. [y/n]"
       send "y\r"
       dropbox autostart y
  EOH
end

The error im getting is:

  * bash[DropboxInstall] action run[2018-04-23T07:47:53+00:00] INFO: Processing bash[DropboxInstall] action run (dropbox::default line 24)
[2018-04-23T07:47:53+00:00] DEBUG: Providers for generic bash resource enabled on node include: [Chef::Provider::Script]
[2018-04-23T07:47:53+00:00] DEBUG: Provider for action run on resource bash[DropboxInstall] is Chef::Provider::Script

    [execute] Starting Dropbox...dropbox: locating interpreter
              dropbox: logging to /tmp/dropbox-antifreeze-umikIQ
              dropbox: initializing
              dropbox: initializing python 2.7.11
              dropbox: setting program path '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/dropbox'
              dropbox: setting home path '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74'
              dropbox: setting python path '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74:/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/python-packages-27.zip'
              dropbox: python initialized
              dropbox: running dropbox
              dropbox: setting args
              dropbox: applying overrides
              dropbox: running main script
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/cryptography.hazmat.bindings._constant_time.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/cryptography.hazmat.bindings._openssl.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/cryptography.hazmat.bindings._padding.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/psutil._psutil_linux.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/psutil._psutil_posix.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/linuxffi.pthread._linuxffi_pthread.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/tornado.speedups.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/cpuid.compiled._cpuid.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/linuxffi.resolv.compiled._linuxffi_resolv.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/linuxffi.sys.compiled._linuxffi_sys.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/posixffi.libc._posixffi_libc.so'
              dropbox: load fq extension '/root/.dropbox-dist/dropbox-lnx.x86_64-47.4.74/librsyncffi.compiled._librsyncffi.so'

The Chef script is completing the installation, but its dieing when it tries to execute the "expect" from the CLI:

              Dropbox is the easiest way to share and store your files online. Want to learn more? Head to https://www.dropbox.com/

              In order to use Dropbox, you must download the proprietary daemon. [y/n] Traceback (most recent call last):
                File "/usr/bin/dropbox", line 1404, in start
                  download()
                File "/usr/bin/dropbox", line 547, in download
                  if not yes_no_question("%s%s" % (WARNING, GPG_WARNING_MSG)):
                File "/usr/bin/dropbox", line 138, in yes_no_question
                  text = raw_input()
              EOFError: EOF when reading a line
              ****/tmp/chef-script20180423-29717-15l42km: line 2: expect: command not found
              /tmp/chef-script20180423-29717-15l42km: line 3: send: command not found****
[2018-04-23T07:48:54+00:00] INFO: bash[DropboxInstall] ran successfully
    - execute "bash"  "/tmp/chef-script20180423-29717-15l42km"

I've no doubt its me, but i've done a bit of reading and cant work out how best to tackle this. It looks like when it tries to execute the bash script, its having issues, but i try and "cat /tmp/chef-script20180423-29717-15l42km" its not there, so i'm not sure how to troubleshoot this one.

Thanks in advance!


Solution

  • file '/tmp/dropbox.sh' do
          mode '0755'
          owner 'root'
          group 'root'
          content 'puts "Running Dropbox Installer..."
                   log_user 0
                   spawn dropbox start -i
                   expect {
                           "*In order to use Dropbox, you must download the proprietary daemon*" {send "y\r"}
                          }
                   exec sleep 360
                           puts "Dropbox installer completed"'
        end
    
        bash 'DropboxInstall' do
          user 'root'
          cwd  '/tmp'
          code <<-EOF
          /usr/bin/expect -d dropbox.sh
          EOF
        end