Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Cannot write to file via post_provision_scripts #880

Closed
filipengberg opened this issue Aug 24, 2016 · 4 comments
Closed

Cannot write to file via post_provision_scripts #880

filipengberg opened this issue Aug 24, 2016 · 4 comments

Comments

@filipengberg
Copy link

After provisioning my box I want to add the path of my composer vendor/bin dir which contains local versions of Drupal Console and Drush downloaded via composer.

To do this I have the following in my config.yml:

post_provision_scripts:
  - "{{ config_dir }}/../scripts/vagrant-post-provision.sh"

My vagrant-post-provision.sh looks like this:

#!/bin/bash

# Add local Drush and Drupal Console to PATH
if ! grep -q /var/www/site/vendor/bin "$HOME/.profile" ; then
  sudo echo "export PATH=/var/www/site/vendor/bin:$PATH" >> $HOME/.profile
else
  exit 0
fi

I don't get any errors while provisioning and it runs the task according to the console output.
However my ~/.profile file does not change.

If I manually do vagrant ssh and run the command
sh /var/www/site/scripts/vagrant-post-provision.sh

It adds a row to my ~/.profile as expected.

Any idea what I might be doing wrong?

@thom8
Copy link
Collaborator

thom8 commented Aug 24, 2016

@reekris this will likely be running with sudo using the root user so would create /root/.profile rather than /home/vagrant/.profile.

You could add it to /etc/profile.d which is loaded for all users -- example - https://github.com/geerlingguy/ansible-role-composer/blob/master/tasks/global-require.yml#L12-L16

However, I prefer to use a .drush-use file in the root of the project -- example - https://github.com/acquia/blt/blob/8.x/template/.drush-use

This way you can tell drush to always use the local version, I'm not sure if drupal console has a similar option.

@filipengberg
Copy link
Author

@thom8 Thanks for the help!

Not sure how I would go about adding my script to /etc/profile.d? Can that be done during provisioning somehow?

Changing my script to point to /home/vagrant/.profile made it work anyway. Not as nice since the vagrant user is hardcoded, but it works.

.drush-use seems like a nice alternative for Drush, but I'm not aware of any similar solution for Drupal Console.

@thom8
Copy link
Collaborator

thom8 commented Aug 24, 2016

Good to hear you've got it working, if you're familiar with anisble you could also use a custom ansible task -- http://docs.drupalvm.com/en/latest/extras/scripts/#ansible-task-files

just include a become: no so it would run without sudo.

BTW - I've got a PR open on the composer role which could solve this too ;) -- geerlingguy/ansible-role-composer#26

@filipengberg
Copy link
Author

Nice! Hopefully it gets merged then 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants