Running deploy within the guest VM on windows : Issue with building assets

I have the provisioning and deploy methods working ok while running ansible inside the VM (using windows) except for a couple of things.

When I uncomment the code in build-before.yml (and change path to the name of my theme ) I get errors in the deploy.

Im assuming this is because for most users ansible will be running on the host, so the paths will be correct. However as I am inside the VM something is messing up. The error is here:

TASK [deploy : Run npm install] ************************************************
task path: /vagrant/deploy-hooks/build-before.yml:7
ESTABLISH LOCAL CONNECTION FOR USER: vagrant EXEC ( umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1454181703.82-191183928288020 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1454181703.82-191183928288020 )" ) PUT /tmp/tmpPyQpSv TO /home/vagrant/.ansible/tmp/ansible-tmp-1454181703.82-191183928288020/command EXEC LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1454181703.82-191183928288020/command; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1454181703.82-191183928288020/" > /dev/null 2>&1
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1454181703.82-191183928288020/command", line 2385, in <module>
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1454181703.82-191183928288020/command", line 188, in main
OSError: [Errno 2] No such file or directory: '/site/web/app/themes/chris-mcnally'

fatal: []: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "command"}, "parsed": false}

The task fails on the first part in the yml file :

 - name: Run npm install
   command: npm install
   connection: local
     chdir: "{{ project.local_path }}/web/app/themes/chris-mcnally"

Has anyone got any ideas ?

The second issue isnt so urgent : I cannot use (again I think this is a windows issue) but I can call the deploy ansible command directly

 - name: Copy project local files
-    src: "{{ project.local_path }}/web/app/themes/sage/dist"
+    src: "{{ project_root }}/current/web/app/themes/sage/dist"
     dest: "{{ deploy_helper.new_release_path }}/web/app/themes/sage"
     group: no
     owner: no
     rsync_opts: --chmod=Du=rwx,--chmod=Dg=rx,--chmod=Do=rx,--chmod=Fu=rw,--chmod=Fg=r,--chmod=Fo=r

I’m not on Windows, so I’m a little uncertain about this, but I think you’ll need to run your npm/bower/gulp commands from either the Windows side or from within the VM, but not both because the differing OS versions may conflict (for node_modules/ etc.).

Do you get any particular error? Is your Trellis version as recent as Jan 16, 2016?

Keep an eye on ansible_local coming soon to Trellis, which should simplify some of your steps on Windows.

1 Like

Thanks for the response, I thought this may be windows limitation…

Sorry, I didn’t see the post you linked to, I have been searching and scratching my head for a while. It probably should be added to the windows docs, with a note in the build-before.yml.

With the, I get the following

vagrant@chrismcnally:/vagrant$ production command not found

And yes, the trellis build was pulled down fresh today

The file is present, its probably permissions/an issue with the mounted folders on windows

Its a shame I need to build the production assets manually before deploy, as I had hoped that this would be an automated deployment process.

I cant complain though, my workflow has drastically improved using the tools here !

Thanks again for your help

When trying to complete the “Copy project local files” task I get the following error :

set_remote_user": true, "src": "/srv/www/", "ssh_args": null, "times": null, "verify_host": false}}, "msg": "rsync: change_dir \"/srv/www/\" failed: No such file or directory (2)\nrsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0]\n", "rc": 23}

Try adjusting your command

- production
+ ./ production

If you remove node_modules etc. I wonder if you could do the npm install etc. all within the VM (exclusively – no longer from the Windows host). This may allow you to use the other tasks in build-before.yml to compile your assets.

failed: No such file or directory

Could you let us know whether this directory is there on the VM?

I think there is a slight chance this directory may not be there on the VM because of a potential problem with your sync directories. Earlier, I believe you tried

"{{ project.local_path }}/web/app/themes/sage/dist"

and that it yielded this error:

No such file or directory: '/site/web/app/themes/chris-mcnally'

This suggests that you have local_path: /site, an absolute path, vs the relative path in the defaults: local_path: ../site. That local_path factors into the setup of sync folders between your Windows host and Vagrant VM and would affect the directory needed for the synchronize task “Copy project local files”.

So, check the VM for the presence of /srv/www/ and double-check your definition of local_path in group_vars/development/wordpress_sites.yml. If that doesn’t lead to resolution, then if you’ve modified the “Copy project local files” from what I displayed above, you could paste your version here. You might also share your wordpress_sites.yml for development and production.

I am running into this problem on Windows as well. The local_path var is using the default ../site value. So the reason he and I both got errors like this:

No such file or directory: '/site/web/app/themes/chris-mcnally'

Is because on the guest machine, the trellis folder is /vagrant, which obviously turns ../site into /site

So the solution for me was right after this line:

config.vm.synced_folder File.join(ANSIBLE_PATH, 'hosts'), File.join(ANSIBLE_PATH.sub(__dir__, '/vagrant'), 'hosts'), mount_options: ['dmode=755', 'fmode=644']

Add this:

# can't deploy on windows when running Vagrantfile from inside trellis folder; make site folder a root folder
config.vm.synced_folder File.join(ANSIBLE_PATH, '../site'), "/site", mount_options: ['dmode=755', 'fmode=644']