drupal-vm icon indicating copy to clipboard operation
drupal-vm copied to clipboard

Post Provision Script Error (Windows 10)

Open sbubaron opened this issue 7 years ago • 2 comments

Issue Type

  • Bug Report / Support Request

Your Environment

Vagrant 2.2.3                                                                                                                                  
VirtualBox 6.0.4r128413                                                                                                                        
bash: ansible: command not found
Drupal VM: 4.9.2

Your OS

  • Windows (10.0.17134 Build 17134 Education)

Full console output

https://gist.github.com/sbubaron/a968d3dc5e13faa8ee078b261f223b5c

TASK [Run configured post-provision shell scripts.] ****************************
failed: [doitsbup.localvm] (item=/vagrant/config/postprovision.sh) => {"changed": true, "item": "/vagrant/config/postprovision.sh", "msg": "non-zero return code", "rc": 127, "stderr": "/bin/sh: 1: /home/vagrant/.ansible/tmp/ansible-tmp-1548784087.34-19395959453845/postprovision.sh: not found\n", "stderr_lines": ["/bin/sh: 1: /home/vagrant/.ansible/tmp/ansible-tmp-1548784087.34-19395959453845/postprovision.sh: not found"], "stdout": "", "stdout_lines": []}
        to retry, use: --limit @/vagrant/drupal-vm/provisioning/playbook.retry

PLAY RECAP *********************************************************************
doitsbup.localvm           : ok=212  changed=2    unreachable=0    failed=1

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

Summary

Attempting to get a post provision script to run and the vagrant provision is failing. Looks very similar to https://github.com/geerlingguy/drupal-vm/issues/1481

Followed @oxyc advice from above issue, I'm using a delegating Vagrantfile

# The absolute path to the root directory of the project. Both Drupal VM and
# the config file need to be contained within this path.
ENV['DRUPALVM_PROJECT_ROOT'] = "#{__dir__}"
# The relative path from the project root to the config directory where you
# placed your config.yml file.
ENV['DRUPALVM_CONFIG_DIR'] = "config"
# The relative path from the project root to the directory where Drupal VM is located.
ENV['DRUPALVM_DIR'] = "drupal-vm"

# Load the real Vagrantfile
load "#{__dir__}/#{ENV['DRUPALVM_DIR']}/Vagrantfile"

Folder Structure is:

.
+-- config
|   +-- config.yml
|   +-- local.config.yml
|   +-- postprovision.sh
+-- drupal_vm
|   +-- default.config.yml (untouched)
|   +-- Vagrantfile (untouched)
+-- web
+-- Vagrantfile

config.yml:

post_provision_scripts:
  - "{{ config_dir }}/postprovision.sh"

postprovision.sh (this fails with anything in it)

#!/bin/bash
echo Hello World

sbubaron avatar Jan 29 '19 17:01 sbubaron

If I specify a file (in config.yml) that doesn't actually exist I get a different error:

TASK [Run configured post-provision shell scripts.] ****************************                                                               failed: [doitsbup.localvm] (item=/vagrant/config/postprovisionX.sh) => {"changed": false, "item": "/vagrant/config/postprovisionX.sh", "msg":  "Could not find or access '/vagrant/config/postprovisionX.sh' on the Ansible Controller.\nIf you are using a module and expect the file to exi st on the remote, see the remote_src option"}                                                                                                          to retry, use: --limit @/vagrant/drupal-vm/provisioning/playbook.retry                                                                                                                                                                                                                PLAY RECAP *********************************************************************                                                               doitsbup.localvm           : ok=212  changed=2    unreachable=0    failed=1

sbubaron avatar Jan 29 '19 17:01 sbubaron

The issue was the line endings in the bash script file. I had to set it to LF instead of CRLF.

I discovered this after trying to run the script in the VM directly and received an error along the lines of: /bin/sh^M: bad interpreter: No such file or directory

sbubaron avatar Feb 07 '19 19:02 sbubaron