Trellis up fails at: TASK [common : Load wordpress_sites.yml vars into <env>_sites vars]

I have a project that I work on with my iMac regularly and I am attempting to get it working on my Macbook but it fails at this line:

TASK [common : Load wordpress_sites.yml vars into <env>_sites vars] ***********************************************************
System info:
  Ansible 2.9.10; Darwin
  Trellis version (per changelog): "Fix #1284 - Update logrotate postrotate Nginx command"
---------------------------------------------------
An unhandled exception occurred while templating '{{ lookup('filetree',
playbook_dir + '/group_vars') | selectattr('path', 'match', '(' + env_groups
| join('|') + ')/wordpress_sites\.yml$') | map(attribute='path') |
map('regex_replace', '([^/]*)/.*', '\1') | list }}'. Error was a <class
'ansible.errors.AnsibleError'>, original message: An unhandled exception
occurred while templating '{{ ['development', 'staging', 'production'] |
intersect(group_names) }}'. Error was a <class
'ansible.errors.AnsibleError'>, original message: template error while
templating string: No filter named 'intersect'.. String: {{ ['development',
'staging', 'production'] | interse

I am unable to find any answers anywhere. Hopefully someone can help my dissect this error message.

Please read How to best ask questions on this forum

This post is lacking critical information such as:

  • All relevant details about your setup

    Operating systems, local/remote environment information, versions of the software that you’re using are all important details that should be provided when asking for help.

  • Minimum reproducible steps

    Demonstrate your issue with a list of instructions that can be followed to replicate it.

Formatting your logs as described in the linked topic will also help the readability of your post.

I think that I ran into the same issue :frowning:

as @joshb I have an iMac in the office and everything works as expected, I have around 10 websites with the roots family (trellis/bedrock/sage)

I just bought a new MacBook Pro M1 and I am trying to work on this as well.

I followed this Vagrant | Trellis Docs | Roots, I bought Parallels Pro and I followed all the steps.

I have done a quick example test to see if trellis/bedrock was working as expected with Parallels Pro, trellis new example.com and then vagrant up and everything work well, so I guess that the MacBook has everything needed to make trellis/bedrock/sage work.

so next step, I tried to work with my existing websites, I cloned the repositories, I added the .vault file within the trellis folder, I created a vagrant.local.yml file (I chose this because I will continue to work on the iMac and the new macbook pro M1 at the same time in different days) with this code always within the trellis folder

---
vagrant_ip: '192.168.50.5'
vagrant_cpus: 1
vagrant_memory: 1024 # in MB
vagrant_box: 'jeffnoxon/ubuntu-20.04-arm64'
vagrant_box_version: '>= 1.0.0'
vagrant_ansible_version: '2.9.10'
vagrant_ansible_python_interpreter: '/usr/bin/python3'
vagrant_skip_galaxy: false
vagrant_mount_type: 'nfs'

vagrant_install_plugins: true
vagrant_plugins:
  - name: vagrant-bindfs
  - name: vagrant-hostmanager

# Array of synced folders:
# - local_path: .
#   destination: /path/on/vm
#   create: false
#   type: nfs
#   bindfs: true
#   mount_options: []
#   bindfs_options: {}
# See https://www.vagrantup.com/docs/synced-folders/basic_usage.html#mount_options
vagrant_synced_folders: []

from my understanding these should be all the steps needed, so I run vagrant destroy -f && vagrant up but I am running into this error

TASK [common : Load wordpress_sites.yml vars into <env>_sites vars] ************
System info:
  Ansible 2.9.8; Vagrant 2.2.18; Darwin
  Trellis Head
---------------------------------------------------
An unhandled exception occurred while templating '{{ lookup('filetree',
playbook_dir + '/group_vars') | selectattr('path', 'match', '(' + env_groups
| join('|') + ')/wordpress_sites\.yml$') | map(attribute='path') |
map('regex_replace', '([^/]*)/.*', '\1') | list }}'. Error was a <class
'ansible.errors.AnsibleError'>, original message: An unhandled exception
occurred while templating '{{ ['development', 'staging', 'production'] |
intersect(group_names) }}'. Error was a <class
'ansible.errors.AnsibleError'>, original message: template error while
templating string: No filter named 'intersect'.. String: {{ ['development',
'staging', 'production'] | intersect(group_names) }}
fatal: [default]: FAILED! => {}

I tried with a different website, and it stucked at the same task (even tho with a kind of different msg

TASK [common : Load wordpress_sites.yml vars into <env>_sites vars] ************
System info:
  Ansible 2.9.8; Vagrant 2.2.18; Darwin
  Trellis version (per changelog): "Fix #1277 - Disable PHP CLI memory limit"
---------------------------------------------------
An unhandled exception occurred while templating '{{ lookup('filetree',
playbook_dir + '/group_vars') | selectattr('path', 'match', '(' + env_groups
| join('|') + ')/wordpress_sites\.yml$') | map(attribute='path') |
map('regex_replace', '([^/]*)/.*', '\1') | list }}'. Error was a <class
'ansible.errors.AnsibleError'>, original message: An unhandled exception
occurred while templating '{{ ['development', 'staging', 'production'] |
intersect(group_names) }}'. Error was a <class
'ansible.errors.AnsibleError'>, original message: template error while
templating string: No filter named 'intersect'.. String: {{ ['development',
'staging', 'production'] | intersect(group_names) }}
fatal: [default]: FAILED! => {}

I tried to change the ansible version multiple times with pip install ansible==2.9.8 and different version but no luck.

what else I can try?

Am I missing some extra step?

any ideas? could anyone point me in the right direction?

@joshb did you find a solution?

thanks

@kurt

I was able to get past this but I don’t recall what I did. It was likely a lot of trial and error, destroying the env, updating parts of trellis, etc… Hopefully someone knows exactly how to resolve here but updating all of Trellis to latest might be the best option for you.

I have exactly the same issues and tried the same as you guys.
What do you think @swalkinshaw?

I think that we need a lot more details as mentioned above to be able to troubleshoot and help.

@kurt did include details which I can look over for his case specifically, but we can’t assume yours is the same.

1 Like

Sorry I’m just seeing this now @kurt, but one thing stands out:

You didn’t mention if you ran trellis init on the existing sites before running vagrant up. Did you run that? If not, that’s my first suggestion. It will ensure you have a Python virtualenv with the proper dependencies installed.

In my case i do a fresh git clone of the project, run trellis init, which installs dependencies. After that i run trellis up and get the same error as @kurt

| => trellis up
- composer (1.7.6) is already installed, skipping.
- ntp (2.0.0) is already installed, skipping.
- logrotate (v0.0.5) is already installed, skipping.
- swapfile (v2.0.26) is already installed, skipping.
- mailhog (2.2.0) is already installed, skipping.

Running command => vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'bento/ubuntu-20.04'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/ubuntu-20.04' version '202112.19.0' is up to date...
==> default: Setting the name of the VM: naanu2.test
==> default: Pruning invalid NFS exports. Administrator privileges will be required...
Password:
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Installing NFS client...
==> default: Exporting NFS shared folders...
==> default: Preparing to edit /etc/exports. Administrator privileges will be required...
==> default: Mounting NFS shared folders...
==> default: Mounting shared folders...
    default: /vagrant => /Users/marko/Projekte/naanu/naanu_23/naanu/trellis
==> default: Checking for bindfs in VM...
    default: Package manager detected: apt-get
    default: Fuse kernel module is installed
    default: Fuse kernel module is loaded
==> default: Bindfs seems to not be installed on the virtual machine, installing now
    default: Bindfs 1.14.1 is installed
==> default: Machine is ready to use bindfs!
==> default: Creating bind mounts after synced_folders...
    default: /vagrant-nfs-example.test => /srv/www/example.test/current
    default: /ansible-nfs => /home/vagrant/trellis
    default: /home/vagrant/trellis/bin => /home/vagrant/trellis/bin
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: Running provisioner: ansible...
    default: Running ansible-playbook...
[WARNING]: Skipping plugin (/Users/project/trellis/
.trellis/virtualenv/lib/python3.9/site-packages/ansible/plugins/filter/core.py)
as it seems to be invalid: cannot import name 'environmentfilter' from
'jinja2.filters' (/Users/project/trellis/.trellis/v
irtualenv/lib/python3.9/site-packages/jinja2/filters.py)
[WARNING]: Skipping plugin (/Users/project/trellis/
.trellis/virtualenv/lib/python3.9/site-
packages/ansible/plugins/filter/mathstuff.py) as it seems to be invalid: cannot
import name 'environmentfilter' from 'jinja2.filters' (/Users/project/trellis/.trellis/virtualenv/lib/python3.9/site-
packages/jinja2/filters.py)

PLAY [Set ansible_python_interpreter] ******************************************

TASK [python_interpreter : Get Ubuntu version] *********************************
ok: [default]

TASK [python_interpreter : Set ansible_python_interpreter for Ubuntu >= 18.04] ***
ok: [default]

PLAY [WordPress Server: Install LEMP Stack with PHP 7.4 and MariaDB MySQL] *****

TASK [Gathering Facts] *********************************************************
ok: [default]

TASK [common : Load wordpress_sites.yml vars into <env>_sites vars] ************
System info:
  Ansible 2.9.9; Vagrant 2.2.9; Darwin
  Trellis version (per changelog): "Officially support Ubuntu 20.04"
---------------------------------------------------
An unhandled exception occurred while templating '{{ lookup('filetree',
playbook_dir + '/group_vars') | selectattr('path', 'match', '(' + env_groups
| join('|') + ')/wordpress_sites\.yml$') | map(attribute='path') |
map('regex_replace', '([^/]*)/.*', '\1') | list }}'. Error was a <class
'ansible.errors.AnsibleError'>, original message: An unhandled exception
occurred while templating '{{ ['development', 'staging', 'production'] |
intersect(group_names) }}'. Error was a <class
'ansible.errors.AnsibleError'>, original message: template error while
templating string: No filter named 'intersect'.. String: {{ ['development',
'staging', 'production'] | intersect(group_names) }}
fatal: [default]: FAILED! => {}

PLAY RECAP *********************************************************************
default                    : ok=3    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
exit status 1

A new release of trellis-cli is available: 1.7.0 → v1.10.1
https://github.com/roots/trellis-cli/releases/tag/v1.10.1

When i run trellis up again, i get this response:

| => trellis up
- composer (1.7.6) is already installed, skipping.
- ntp (2.0.0) is already installed, skipping.
- logrotate (v0.0.5) is already installed, skipping.
- swapfile (v2.0.26) is already installed, skipping.
- mailhog (2.2.0) is already installed, skipping.

Running command => vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/ubuntu-20.04' version '202112.19.0' is up to date...
==> default: [vagrant-hostmanager:guests] Updating hosts file on active guest virtual machines...
==> default: [vagrant-hostmanager:host] Updating hosts file on your workstation (password may be required)...
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
==> default: Running action triggers after up ...
==> default: Running trigger...
==> default: Adding vagrant ssh-config for example.test to ~/.ssh/config

==> default: Machine 'default' has a post `vagrant up` message. This is a message
==> default: from the creator of the Vagrantfile, and not from Vagrant itself:
==> default: 
==> default: Your Trellis Vagrant box is ready to use!
==> default: * Composer and WP-CLI commands need to be run on the virtual machine
==> default:   for any post-provision modifications.
==> default: * You can SSH into the machine with `vagrant ssh`.
==> default: * Then navigate to your WordPress sites at `/srv/www`
==> default:   or to your Trellis files at `/home/vagrant/trellis`.

Thanks @maroluke! Your extra Vagrant output logs provided the root cause.

[WARNING]: Skipping plugin (/Users/project/trellis/
.trellis/virtualenv/lib/python3.9/site-packages/ansible/plugins/filter/core.py)
as it seems to be invalid: cannot import name 'environmentfilter' from
'jinja2.filters' (/Users/project/trellis/.trellis/v
irtualenv/lib/python3.9/site-packages/jinja2/filters.py)
[WARNING]: Skipping plugin (/Users/project/trellis/
.trellis/virtualenv/lib/python3.9/site-
packages/ansible/plugins/filter/mathstuff.py) as it seems to be invalid: cannot
import name 'environmentfilter' from 'jinja2.filters' (/Users/project/trellis/.trellis/virtualenv/lib/python3.9/site-
packages/jinja2/filters.py)

The other error “No filter named ‘intersect’” now makes sense because Ansible skipped loading its core filter plugin so it’s not surprising that something wouldn’t work.

From my quick searching, this is due to the jinja2 Python package having a breaking change in v3. This likely means any Trellis (and by proxy Ansible) project using ansible <= 2.13 is now broken.

All 3 people that have posted in this thread are running Ansible 2.9.x which explains all the issues.

There are two solutions to this:

  1. upgrade your ansible version to match Trellis’ current requirement
  2. downgrade your jinja2 version. You can do this by adding the following to your requirements.txt file:
jinja2<3.0

For a quicker fix, I suggest the 2nd option since it’s the most straightforward change. If you upgrade Ansible, you might have to upgrade Trellis too.

Note: if you ever upgrade your project back to a newer Ansible version, you’ll want to remove that jinja2 line.

2 Likes

Thanks @swalkinshaw. I appreciate your effort.
I have still some errors, but they are different.
When i run trellis up:

Error while installing Ansible Galaxy roles:
Traceback (most recent call last):
  File "/Users/project/trellis/.trellis/virtualenv/bin/ansible-galaxy", line 62, in <module>
    import ansible.constants as C
  File "/Users/project/trellis/.trellis/virtualenv/lib/python3.9/site-packages/ansible/constants.py", line 12, in <module>
    from jinja2 import Template
  File "/Users/project/trellis/.trellis/virtualenv/lib/python3.9/site-packages/jinja2/__init__.py", line 12, in <module>
    from .environment import Environment
  File "/Users/project/trellis/.trellis/virtualenv/lib/python3.9/site-packages/jinja2/environment.py", line 25, in <module>
    from .defaults import BLOCK_END_STRING
  File "/Users/project/trellis/.trellis/virtualenv/lib/python3.9/site-packages/jinja2/defaults.py", line 3, in <module>
    from .filters import FILTERS as DEFAULT_FILTERS  # noqa: F401
  File "/Users/project/trellis/.trellis/virtualenv/lib/python3.9/site-packages/jinja2/filters.py", line 13, in <module>
    from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/Users/project/trellis/.trellis/virtualenv/lib/python3.9/site-packages/markupsafe/__init__.py)

This may be a temporary network issue. Please try again.
Running command => vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'bento/ubuntu-20.04'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/ubuntu-20.04' version '202112.19.0' is up to date...
==> default: Setting the name of the VM: naanu2.test
==> default: Pruning invalid NFS exports. Administrator privileges will be required...
Password:

$ pyenv which python
$ /Users/me/.pyenv/versions/3.9.7/bin/python

I googled for that error message which led me to this: python - ImportError: cannot import name 'soft_unicode' from 'markupsafe' - Stack Overflow

Looks like because we downgraded jinja2 we also need to downgrade markupsafe

So try adding this to your requirements.txt as well:

jinja2<3.0
markupsafe==2.0.1

And run trellis init --force just to ensure you get those versions.

2 Likes

Finally!!! You don’t know how long i was trying to fix it :woozy_face:
Thank you so much for your invaluable advice @swalkinshaw.
I’m sure this will help others as well.
Happy coding!

1 Like