Roots Discourse

Vagrant Up error with new v. of Trellis


#1

I’m trying the new simplified version of Trellis for the first time, and when I vagrant up, I’m getting this error:

TASK [wordpress-setup : Create database of sites] ****************************** INFO interface: detail: fatal: [default]: FAILED! => {"failed": true, "msg": "ERROR! template error while templating string: no filter named 'underscore'"}

fatal: [default]: FAILED! => {"failed": true, "msg": "ERROR! template error while templating string: no filter named 'underscore'"}

I tried running it in verbose mode and got the same thing. Other than a play recap, I don’t see any extra error logging.

I’m assuming it has to do with the lib/trellis/plugins/filter/filters.py or the group_vars/all/main.yml.

Anyone seen this error before or know what no filter named 'underscore' is refering to?

Here’s my repo.

Edit: Meanwhile, I’m going to spin up a new version to see if I re-encounter this problem.


Getting an error while creating Trellis dev database
#2

roots/trellis#538 moved file with the custom filters for Trellis. This change works fine when Ansible/Vagrant commands are run from the trellis directory. I neglected to test moving the Vagrantfile to a parent directory, as you have done in your project. I’ll work on a fix.

In the meantime, you have a couple options.

1 - Move the Vagrantfile back to the trellis directory, as is the current recommendation in the roots-example-project.com repo. If you choose this option, remember to restore this default in your Vagrantfile: ANSIBLE_PATH = __dir__.

2 - I think the option above is better, but an alternative may be to edit some paths in your ansible.cfg. The paramters callback_plugins, filter_plugins, library, and vars_plugins each include a list of paths, the final path in each beginning with lib/trellis/. I think you’ll need to prepend trellis to each (now trellis/lib/trellis) so they can dig down into the trellis subdirectory (relative to your moved Vagrantfile).


#3

Thanks Phil!

I headed your advice and went for route #1. I somehow missed when the Vagrantfile moved back into Trellis.

I hit this weird error where vagrant up was hanging at Bindfs install. So I continued respinning a fresh install. Vagrant up worked. But I ran into another issue which I’ll start a new thread for assuming it’s un-related.


#4

Glad option 1 worked. Looking into the issue a little more, a third option may have been to just cd into your trellis dir before running vagrant up. Vagrant will look in parent directories for a Vagrantfile, so that works, and with the trellis dir as the cwd, Ansible should probably load the custom filters, plugins, etc.

I’ve proposed a fix, however, in roots/trellis#552


#5

@fullyint:
Because I am using a separate Vagrantfile for staging system, I chosed the 2nd approach and
added extra paths relative to new staging/ folder in which the Vagrantfile for staging resides.

However, underscore still cannot be found. Current ansible.cfg:

[defaults]
callback_plugins = ~/.ansible/plugins/callback_plugins/:/usr/share/ansible_plugins/callback_plugins:lib/trellis/plugins/callback:../lib/trellis/plugins/callback
stdout_callback = output
filter_plugins = ~/.ansible/plugins/filter_plugins/:/usr/share/ansible_plugins/filter_plugins:lib/trellis/plugins/filter:../lib/trellis/plugins/filter
force_color = True
force_handlers = True
inventory = hosts
nocows = 1
roles_path = vendor/roles
vars_plugins = ~/.ansible/plugins/vars_plugins/:/usr/share/ansible_plugins/vars_plugins:lib/trellis/plugins/vars:../lib/trellis/plugins/vars

The modifications should still leave the ansible.cfg working with
development Vagrantfile and ansible-playbook on remote systems/servers.

So default/stock Vagrantfile is in project root (./Vagrantfile) while
Vagrantfile for staging resides in ./staging/Vagrantfile (hence the ../ in ansible.cfg).


#6

@strarsis I haven’t thought through your goals and the implications for what else you might run into. But just on the specific topic of paths to Ansible filter plugins in the context of a moved Vagrantfile

In general when you move a Vagrantfile, I believe all you need to do is update the ANSIBLE_PATH in the Vagrantfile. When Vagrant is involved, Trellis sets environment variables for paths to the various Ansible plugins, and does so based on the value of ANSIBLE_PATH. These env variables should override values in ansible.cfg

So, if you update ANSIBLE_PATH in the Vagrantfile, I wouldn’t have expected any additional edits to be required to make the Ansible plugins accessible.

In any case, I’d sure be inclined to put a staging server on the same (or scaled down) type of cloud server I intend to use for production, for the sake of parity and avoiding Vagrant hassles. But I imagine you have your reasons.


#7

@fullyint: Thanks, this works nicely. The reason for why I want to run a staging instance locally/on a VM is in order to test some changes/optimizations to the deploy task before trying it out on real staging or even on production. Related:


#8

:arrow_up: Ok, makes sense.

An alternative that may be easier:

  • Create new test server and get IP
  • Copy hosts/staging to hosts/test and in the contents…
    • add new IP
    • replace [staging] with [test]
  • Copy group_vars/staging to group_vars/test and adjust wordpress_sites as you please
  • ansible-playbook server.yml -e env=test
  • ansible-playbook deploy.yml -e env=test -e site=example.com

#9

I ran into this and eventually found that it was because one of the Trellis Ansible plugins were being overridden by a role.

The filename of the filter plugin lib/trellis/plugins/filter/filters.py was the same as a filter plugin in one of the roles we are using (MichaelRigart.interfaces). So the role’s plugin was overriding the Trellis one, causing the error above about the missing underscore filter.

This can be fixed by renaming the Trellis plugin file to trellis-filters.py (or something else unique).

This “plugin override” function in Ansible seems very poorly documented, and I have no idea how to fix a conflict between two roles that share a plugin filename.

Here are some references I found to this feature: