Bower / Gulp tasks fail on deploy (build-before.yml)

This is my first Trellis/Bedrock/Roots project, and I’ve run into and solved a number of issues getting here and I’ve learned tonnes, but now I’m stumped. I’ve got as far as deploying successfully, and then manually run the npm/bower/gulp tasks on the server. Now I’ve uncommented the build-before tasks. The deployment runs into this error:

TASK [deploy : include] ********************************************************
included: /Users/Bed/Sites/find-enlight.com/trellis/deploy-hooks/build-before.yml for 46.101.87.215

TASK [deploy : Run npm install] ************************************************
changed: [46.101.87.215]

TASK [deploy : Run bower install] **********************************************
System info:
  Ansible 2.1.1.0; Darwin
  Trellis at "Upgrade Ubuntu from 14.04 Trusty to 16.04 Xenial"
---------------------------------------------------
[Errno 2] No such file or directory
fatal: [46.101.87.215]: FAILED! => {"changed": false, "cmd": "bower install", "failed": true, "rc": 2}

And with increased verbosity, just the bower task:

TASK [deploy : Run bower install] **********************************************
task path: /Users/Bed/Sites/find-enlight.com/trellis/deploy-hooks/build-before.yml:13
File lookup using /Users/Bed/.ssh/id_rsa.pub as file
<46.101.87.215> ESTABLISH LOCAL CONNECTION FOR USER: Bed
<46.101.87.215> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1472297631.37-102758408774136 `" && echo ansible-tmp-1472297631.37-102758408774136="` echo $HOME/.ansible/tmp/ansible-tmp-1472297631.37-102758408774136 `" ) && sleep 0'
<46.101.87.215> PUT /var/folders/b7/ndnvqhzn1db3hb9vyktj9bn80000gn/T/tmpLulu4h TO /Users/Bed/.ansible/tmp/ansible-tmp-1472297631.37-102758408774136/command
<46.101.87.215> EXEC /bin/sh -c 'LANG=en_GB.UTF-8 LC_ALL=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 /usr/bin/python /Users/Bed/.ansible/tmp/ansible-tmp-1472297631.37-102758408774136/command; rm -rf "/Users/Bed/.ansible/tmp/ansible-tmp-1472297631.37-102758408774136/" > /dev/null 2>&1 && sleep 0'
System info:
  Ansible 2.1.1.0; Darwin
  Trellis at "Upgrade Ubuntu from 14.04 Trusty to 16.04 Xenial"
---------------------------------------------------
[Errno 2] No such file or directory
fatal: [46.101.87.215]: FAILED! => {"changed": false, "cmd": "bower install", "failed": true, "invocation": {"module_args": {"_raw_params": "bower install", "_uses_shell": false, "chdir": "../site/web/app/themes/find-enlight-theme", "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 2}

This is my build-before.yml config:

 - name: Run npm install
   command: npm install
   connection: local
   args:
     chdir: "{{ project.local_path }}/web/app/themes/find-enlight-theme"

 - name: Run bower install
   command: bower install
   connection: local
   args:
     chdir: "{{ project.local_path }}/web/app/themes/find-enlight-theme"

 - name: Run gulp
   command: gulp --production
   connection: local
   args:
     chdir: "{{ project.local_path }}/web/app/themes/find-enlight-theme"

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

And here’s the staging wordpress-sites.yml config:

wordpress_sites:
  find-enlight.com:
    site_hosts:
      - canonical: staging.find-enlight.com
        redirects:
          - www.staging.find-enlight.com
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    repo: git@github.com:thisolivier/find-enlight-combo.git
    repo_subtree_path: site
    branch: testingmajor
    admin_email: my@email.uk
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: self-signed
    cache:
      enabled: false

Bower install runs fine from the theme directory, and if I skip the bower task, the same error occurs for the gulp task. The directory for the project/theme seems to be fine, I think it’s the location the commands are being run from, but since (as far as I understand) the remote server is establishing a connection to my local machine to run these commands, I’m totally lost at what the next debug stage is.

You mentioned that you can “manually run the npm/bower/gulp tasks on the server,” (italics mine) so when you mentioned “Bower install runs fine from the theme directory,” I wondered whether you were trying the manual bower install on the server or on your local machine. Do you get a successful bower install on your local machine when you are in the directory below ?

/Users/Bed/Sites/find-enlight.com/site/web/app/themes/find-enlight-theme

Trellis/Ansible operates as your local machine acting as “control machine,” reaching out to run commands on other machines. The connection: local in the Run bower install task is an instruction for the control machine to “reach out” to itself–make a local connection–to run the command from the directory listed in the chdir parameter. I only mention it to correct your statement “(as far as I understand) the remote server is establishing a connection to my local machine to run these commands.”

So, your local machine will need a bower.json in the directory find-enlight.com/site/web/app/themes/find-enlight-theme. Maybe you already have it, but I thought I’d check to be certain.

The build-before.yml is following the “Locally Compile and Upload Assets” strategy of @austin’s Build Steps and Deployment.

I do have the bower.json file, bower install succeeds when run on the local machine from the theme directory. I’d add that the development virtual server works perfectly. Thanks for the information about how Trellis/Ansible are operating, that makes sense, though now I really don’t understand why I’m having this error.

Regarding the confusion over me running the tasks on the remote server, I only manually ran the tasks on the server for my first staging deployment- I found (as expected) that the theme assets hadn’t been built, so I installed the necessary software on the remote server so I could run the npm / bower / gulp tasks.

I’ve since destroyed and rebuilt the server (digital ocean droplet), and then tried to run the deployment with the build-before tasks since it seemed much more secure and efficient.

This is quite strange. I cannot reproduce on Ansible 2.1.1.0 or 2.0.2.0, using your same chdir path. I’m afraid I don’t have any good ideas.

You might test a few things, trying the deploy again after each:

  • setting hard-coded chdir: /Users/Bed/Sites/find-enlight.com/site/web/app/themes/find-enlight-theme
  • changing command: bower install to shell: bower install
  • running which bower then use that full path, e.g.: shell: /usr/local/bin/bower install
  • googling "[Errno 2] No such file or directory" ansible command

Sorry I can’t be of more help.

While digging about, I noticed that I seem to have files from two different versions of trellis- no idea why, but I think my trellis installation was broken.

I’ve reinstalled trellis/bedrock, which should resolve things, only now I’m squarely in the middle of issue #646, but I think I just solved THAT, so now, fingers crossed, I’ll have the site running again soon.


Edit - Having got everything up and running again, I’m now faced with the same issue. I’m trying your steps.

1 Like

Thank you so much for your help, the issue is now resolved. Setting chdir manually didn’t make any difference, but changing command: bower install to shell: bower install gave me this lovely error:

TASK [deploy : Run bower install] **********************************************
task path: /Users/Bed/Sites/find-enlight.com/trellis/deploy-hooks/build-before.yml:13
File lookup using /Users/Bed/.ssh/id_rsa.pub as file
<46.101.87.215> ESTABLISH LOCAL CONNECTION FOR USER: Bed
<46.101.87.215> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1472683112.87-238492643061754 `" && echo ansible-tmp-1472683112.87-238492643061754="` echo $HOME/.ansible/tmp/ansible-tmp-1472683112.87-238492643061754 `" ) && sleep 0'
<46.101.87.215> PUT /var/folders/b7/ndnvqhzn1db3hb9vyktj9bn80000gn/T/tmpSRHYSH TO /Users/Bed/.ansible/tmp/ansible-tmp-1472683112.87-238492643061754/command
<46.101.87.215> EXEC /bin/sh -c 'LANG=en_GB.UTF-8 LC_ALL=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 /usr/bin/python /Users/Bed/.ansible/tmp/ansible-tmp-1472683112.87-238492643061754/command; rm -rf "/Users/Bed/.ansible/tmp/ansible-tmp-1472683112.87-238492643061754/" > /dev/null 2>&1 && sleep 0'
System info:
  Ansible 2.1.1.0; Darwin
  Trellis at "Fix #639 - WP 4.6 compatibility: update WP-CLI to 0.24.1"
---------------------------------------------------
/bin/sh: bower: command not found
fatal: [46.101.87.215]: FAILED! => {"changed": true, "cmd": "bower install", "delta": "0:00:00.007741", "end": "2016-08-31 23:38:33.081087", "failed": true, "invocation": {"module_args": {"_raw_params": "bower install", "_uses_shell": true, "chdir": "../site/web/app/themes/find-enlight-theme", "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 127, "start": "2016-08-31 23:38:33.073346", "stderr": "/bin/sh: bower: command not found", "stdout": "", "stdout_lines": [], "warnings": []}

It seems bower wasn’t installed globally, running npm install -g bower and then trying to deploy again worked perfectly. Could you explain what the difference between the shell and command options are?

Nice work!

This explanation is pretty good: http://stackoverflow.com/a/27735579

1 Like

I had the same problem here, seeing:

TASK [deploy : Run bower install] **********************************************
...
[Errno 2] No such file or directory

In my case, the solution was not immediately obvious: I use nvm (Node version manager), and I had forgotten that I had recently switched to a new version of Node, which in turn uses a different version of npm, which didn’t yet have bower installed globally. Switching back to the previous version solved it. Simply doing an npm install -g bower on the current version would have also solved it.

I hope this solution might help others who run into this problem.

2 Likes

This was the source of my issues too. I’ve now got in the habit of checking the node version once I’m in a directory, or setting aliases for moving to a project and changing my node version.

For some reason I’ve never got .nvmrc files to work for me, which should solve the issue.

2 Likes

How to use nvmrc + yarn (npm) install on deploy:

1 Like