Roots Discourse

Can't deploy from local vagrant

#1

This is an issue we’ve been experiencing ever since trying to deploy Trellis from Windows computers. I’ve tried replicating the issue from my own computer (OSX) and it is exactly the same.

Since ansible doesn’t run on Windows the appropriate workflow to deploy from windows machine is to ssh into the local vagrant box (with ssh vagrant) and move to the trellis directory (~/trellis) then run the commands from there.

I’ve tried running the commands from both ~/trellis and /vagrant but I always get the ./bin/deploy.sh: line 45: ansible-playbook: command not found.

Everything works as expected if I deploy the site from OSX with ansible installed rather than connecting to the host machine and trying to deploy from there.

0 Likes

#2

Hi,
Did you follow the documentation to install Ansible on the VM?

0 Likes

#3

Is your vagrant box provisioned? I don’t know how you could SSH in without it being provisioned since it happens on the first vagrant up, unless there was an error.

0 Likes

#4

There is no need to install ansible on the VM manually when running from windows correct? @MWDelaney

0 Likes

#5

I’m going by the error ,essage you received: ansible-playbook: command not found.

This tells me the command isn’t available, and so ansible isn’t installed on your VM.

0 Likes

#6

If I try to install it in my VM via ansible-galaxy install I get the exact same error.

0 Likes

#7

ansible-galaxy install doesn’t install Ansible, it installs your project’s required Ansible roles.

To test whether Ansible is installed on your VM, try to ssh to the VM and run ansible --version.

0 Likes

#8

No this should be one of the first things done during the provision.

0 Likes

#9

@kalenjohnson it seems to me that Ansible just isn’t installed on the VM.

@zigav can you try backing up your database and doing (whatever the Windows equivalent of) vagrant destroy && vagrant up to see if it just went wrong the first time?

0 Likes

#10

Right, that’s what i mean, if Ansible is not installed on the host machine then it should be installed first thing on the VM.

0 Likes

#11

Did you ever find the solution for this on Windows?

I also get the “ansible-playbook: command not found” error when running:
./bin/deploy.sh staging sitename.com

Update: seems like I have to vagrant ssh and cd trellis to run this command
You get more errors due to the formatting of windows files but you can fix those using this sublime text guide:
https://stackoverflow.com/questions/14219092/bash-my-script-bin-bashm-bad-interpreter-no-such-file-or-directory

0 Likes

#12

See “Running Ansible Commands” here:

0 Likes

#13

Thanks, yes, I figured this much out I think.

I can SSH to my server from command prompt but I cannot run ./bin/deploy.sh due to it not being available on windows.

If I vagrant SSH to run the command then the script does run but in the end I am presented with a
SSH Error: data could not be sent to remote host - UNREACHABLE! message.

I’ll try again but I have no idea where to start at the moment. My best guess is that my local windows .id_rsa.pub isn’t being sent by vagrant? Maybe vagrant sends it’s own key files with this method?

I wonder if there is an easy way to deploy directly if I ssh to the remote server?

0 Likes

#14

Not that’s supported by Trellis.

Have you read the section of that same page about key forwarding?

0 Likes

#15

I have indeed. I am using the Git shell that comes with Git for Windows so ssh-agent should be automatically launched, according to the article that is linked in the docs.

I have tried this with putty too and enabled agent forwarding. Same result.

UPDATE: Still not working and I have tried the following:

If anybody has any ideas they would be much appreciated. For the moment I have to get my Mac developer to deploy the code. :expressionless:

0 Likes

#16

I’m still having problems with this one.

I can actually SSH to the remote server from within the vagrant box, so SSH keys are clearly being sent by vagrant.

I had a theory that the ‘root’ username was not being passed to the server when issuing the deploy command from the vagrant box. Perhaps I need to configure something differently?

If I update my hosts/staging file to the following:

[staging]
root@XXX.XXX.XXX.XXX

[web]
root@XXX.XXX.XXX.XXX

Then I get a little further. A different error is produced though:

TASK [deploy : Install npm dependencies] *******************************************************************************
System info:
Ansible 2.7.5; Linux
Trellis 1.0.0: December 27th, 2018

[Errno 2] No such file or directory
fatal: [root@XXX.XXX.XXX.XXX -> localhost]: FAILED! => {“changed”: false, “cmd”: “yarn”, “rc”: 2}

0 Likes

#17

Just to keep this post up to date… I still can’t deploy from Windows.

Seems there is a new guide for windows and how to use ansible from the windows linux subsystem:
https://roots.io/getting-started/docs/windows-development-environment-trellis/

I have managed to set it up as described and I can now run the ansible deploy command directly from the WLS prompt without ssh’ing to vagrant:
./bin/deploy.sh staging website.ie

But now I have a new errors:

 [WARNING] Ansible is being run in a world writable directory (/mnt/c/dev/example.com/trellis), ignoring it as an ansible.cfg source. For more information see https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAY [Ensure necessary variables are defined] ***********************************************************************************************************************************************************

TASK [Ensure environment is defined] ********************************************************************************************************************************************************************
skipping: [localhost]
 [WARNING]: Could not match supplied host pattern, ignoring: web

 [WARNING]: Could not match supplied host pattern, ignoring: staging


PLAY [Test Connection] **********************************************************************************************************************************************************************************
skipping: no hosts matched

PLAY [Deploy WP site] ***********************************************************************************************************************************************************************************
skipping: no hosts matched

PLAY RECAP **********************************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=0
0 Likes

#18

The error is telling you what’s wrong: ansible is being run from a world-writeable directory. This is because WSL’s default strategy for handling the conversion from Windows permissions to Linux permissions is to just make everything writeable by everyone (not really ideal). The link in the error should get you on the path to fixing it: https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir You’ll need to enable ‘metadata’ on the mount where your project is, and then give it some more reasonable permissions.

1 Like

#19

Cheers for that. It’s a lot to process at the moment but I’ll have another look soon.

0 Likes

#20

Well I figured out the permissions errors with help from @alwaysblank

But I am back to square one with the same error I was getting when running my deploy commands directly from vagrant:

fatal: [XXX.XXX.XXX.XXX]: UNREACHABLE! => {"changed": false, "unreachable": true}

Now I have to figure out how to load my SSH keys into WSL :roll_eyes:

0 Likes