Roots Discourse

Trellis deploy resolves in an ansible error

Hi there, if i execute trellis deploy production i get this error:

Running command => ansible-playbook deploy.yml -e env=production site=***.ch
Traceback (most recent call last):
  File "/Users/user/project/trellis/.trellis/virtualenv/bin/ansible-playbook", line 34, in <module>
    from ansible import context
ModuleNotFoundError: No module named 'ansible'

What’s the problem here?

Maybe this has something to do with this issue: when i’m working on this trellis project i always had to return node to 10.20.1, so i switched to that version with n version manager. I noticed a permission denied message due during the process and it looks like this:

So i tried to execute ansible-playbook deploy.yml -e " env=production" -vvv and got this:

Looks like a broken ansible installation to me.
Note: Ansible is run on the client/workstation by the way, not on the server/target system.

Ensure that the right ansible version is installed for your Trellis project (current Trellis upstream supports ansible up to 2.9.10.

I prefer to install ansible using pip:
You can specify the exact version of ansible to be installed by pip.

If there are still issues with ansible, uninstall all ansible python packages (e.g. using pip) and system packages (e…g using apt) and re-install it again.

1 Like

Thank’s for your inputs.
Ok, first i checked my Ansible version.
Then i executed:
=> pip install --user ansible
and got this:

So should i first update python to the lts version?
Weird: until recently it always worked with these versions.

You can switch to Python 3, it should work with Trellis.

On most distributions you can switch between python 2 and 3.

Localy or on the vagrant machine?

I don’t get it.
Checking my Ansible Version with ansible --version and get this:
ansible 2.9.10

But bellow the version number i get more information and one line is:
python version = 2.7.16 (default, Mar 25 2021, 03:11:28) [GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc-

So i’m wondering why is there python version 2.7.16?
So checking python version with python -V:
Python 3.9.7

But when i do pip install ansible==2.9.10 i get a warning message with:
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at

I don’t understand :frowning:

Ok, i executed ansible-playbook deploy.yml -e " env=production" and it worked.
Deploy was successfull, but i had 2 warnings:

  1. [WARNING]: Skipping plugin (/Users/user/Library/Python/2.7/lib/python/site-packages/ansible/plugins/connection/ as it seems to be invalid: cannot import name key_for_hostname

  2. [DEPRECATION WARNING]: Distribution Ubuntu 20.04 on host *** should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See for more information. This feature will be removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

So what should i do?

Anyway, trellis deploy production still doesn’t work.

You probably used python 2 pip, not python 3 (python3) pip. Try pip3 command instead. You can also uninstall the python 2 pip-installed ansible to be sure that python 3 pip-installed ansible is used.

Trellis CLI should have activated virtualenv with the correct python version for you automatically.

Do you see [trellis] activated env (or similar) when you cd into the trellis folder?

Learn more at:

This topic was automatically closed after 42 days. New replies are no longer allowed.