Ansible get wrong theme directory for second site in trellis

I’ve successfully provisioned and deployed one site with trellis. Ive managed to provision to add another site but when i deploy i get the following error:

TASK [deploy : Run npm install] ************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: OSError: [Errno 2] No such file or directory: '/Users/kristoffer/Sites/cristea/web/app/themes/webnerds'
fatal: [82.102.5.250]: FAILED! => {"changed": false, "failed": true, "parsed": false}

Ive tried to run with the -vvv flag but it gives no additional info.

webnerds is what the theme is called for my other site so it seems as if Trellis is mixing up these in some way. Any suggestions on how i might solve this?

What are the contents of your deploy-hooks/build-before.yml file?

2 Likes

@ben: Ah! Seems i have the settings for the old site in deploy-hooks/build-before.yml. Thank you! It looks lite this:

# Placeholder `deploy_build_before` hook for building theme assets locally
# and then copying the files to the remote server
#
# Uncomment the lines below and replace `sage` with your theme folder
#
# ---
- name: Run npm install
  command: npm install
  connection: local
  args:
    chdir: "{{ project.local_path }}/web/app/themes/webnerds"

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

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

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

However. Can i create different deploy hooks for different sites in group_vars/{env}/wordpress_sites.yml? Or is it better to use one Trellis clone for each site? (The sites have no relation other than that they are hosted on the same vps)

I found a solution but i dont know if its the best.

In production/wordpress_sites.yml i added a setting theme: {my_theme_folder}.
Then in deploy-hooks/build-before.yml i added:

chdir: "{{ project.local_path }}/web/app/themes/{{project.theme}}"

Tnx for help!

1 Like

That can work. There’s another solution you could do as well. You could define your hook file like this:

deploy_build_after: "hooks/{{ site }}/deploy-hooks/build-after.yml"

Then you could create a directory for each site name and put a different build-after.yml file in there.

1 Like