Ansible upgrade breaks access to all other trellis deploys

Hello,

I created a new trellis site the other day and saw that the requirements step had changed slightly and that when I went through it, it upgrade my version of ansible.

I just tried to deploy and older site and received: ‘PlaybookCLI’ object has no attribute ‘options’.

After searching around, I realized it was the ansible upgrade so I downgraded and all is well.

I will need to create more sites soon and am not sure what to do here.

I found this post about virtualenvs: Updated to Ansible 2.4, deploys broken, now what?

Is this the best way to deal with different sites that use different ansible versions or is there a quick way to upgrade all my older sites or what?

Any help is appreciated.

Thanks!
Josh

It depends on a few things such as:

  • how many projects you have
  • how old they are
  • how customized they are

Trellis did get support for Ansible 2.8 in https://github.com/roots/trellis/pull/1103 but you’d have to apply those changes to all your projects.

Using virtualenv for different versions is likely the best way to proceed.

Should also mention that trellis-cli just got a new feature to manage virtualenvs + dependencies automatically. I think the process would be:

  1. manually add a requirements.txt to all projects that don’t have it (based on https://github.com/roots/trellis/blob/master/requirements.txt) but set the version of Ansible you want.
  2. run trellis init within that project dir and a virtualenv will be created + pip dependencies installed
  3. use trellis cli for subsequent commands (or trellis exec <any ansible command>) to run it within the virtual env
1 Like

Thank you Scott!

Trying this out now… do I run init in the trellis dir or in the root of the proj that contains site and trellis dir?

:thinking: either works if I remember correctly. trellis-cli detects project structures and handles things properly (at least it should!)

Hey Scott,

I initiated trellis to one of my projects and now am redoing the requirements step of my newer version and ran into this error which I did not experience the first time my Ansible was updated:

Found existing installation: ansible 2.7.5
Uninstalling ansible-2.7.5:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: ‘/usr/local/lib/python2.7/site-packages/ansible-2.7.5-py2.7.egg-info/PKG-INFO’
Consider using the --user option or check the permissions.

Any idea why this is happening now? My command was: pip install -r requirements.txt

Thank you!

I guess I can just add --user to the command but definitely didn’t have to a week ago when I ran the same pip install command in my trellis directory.

You just ran pip install -r requirements.txt on its own? If you could list the steps you took/commands you ran in order it might help figure out what happened.

Sure can:

**trellis3** ] $ pip install -r requirements.txt

Collecting ansible<2.9,>=2.7.12 (from -r requirements.txt (line 1))

Requirement already satisfied: passlib in /usr/local/lib/python2.7/site-packages (from -r requirements.txt (line 2)) (1.7.1)

Requirement already satisfied: cryptography in /usr/local/lib/python2.7/site-packages (from ansible<2.9,>=2.7.12->-r requirements.txt (line 1)) (2.7)

Requirement already satisfied: jinja2 in /usr/local/lib/python2.7/site-packages (from ansible<2.9,>=2.7.12->-r requirements.txt (line 1)) (2.10.1)

Requirement already satisfied: PyYAML in /usr/local/lib/python2.7/site-packages (from ansible<2.9,>=2.7.12->-r requirements.txt (line 1)) (5.1.2)

Requirement already satisfied: enum34; python_version < "3" in /usr/local/lib/python2.7/site-packages (from cryptography->ansible<2.9,>=2.7.12->-r requirements.txt (line 1)) (1.1.6)

Requirement already satisfied: cffi!=1.11.3,>=1.8 in /usr/local/lib/python2.7/site-packages (from cryptography->ansible<2.9,>=2.7.12->-r requirements.txt (line 1)) (1.12.3)

Requirement already satisfied: six>=1.4.1 in /usr/local/lib/python2.7/site-packages (from cryptography->ansible<2.9,>=2.7.12->-r requirements.txt (line 1)) (1.11.0)

Requirement already satisfied: asn1crypto>=0.21.0 in /usr/local/lib/python2.7/site-packages (from cryptography->ansible<2.9,>=2.7.12->-r requirements.txt (line 1)) (0.24.0)

Requirement already satisfied: ipaddress; python_version < "3" in /usr/local/lib/python2.7/site-packages (from cryptography->ansible<2.9,>=2.7.12->-r requirements.txt (line 1)) (1.0.22)

Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python2.7/site-packages (from jinja2->ansible<2.9,>=2.7.12->-r requirements.txt (line 1)) (1.1.1)

Requirement already satisfied: pycparser in /usr/local/lib/python2.7/site-packages (from cffi!=1.11.3,>=1.8->cryptography->ansible<2.9,>=2.7.12->-r requirements.txt (line 1)) (2.19)

Installing collected packages: ansible

Found existing installation: ansible 2.7.5

Uninstalling ansible-2.7.5:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/ansible-2.7.5-py2.7.egg-info/PKG-INFO'

Consider using the `--user` option or check the permissions.

Ok, I just realized when I downgraded ansible with: sudo pip install ansible==2.7.5

This caused all my older deploys to work again but it might not have been the best way to downgrade?

So maybe I should uninstall with sudo and run a requirements.txt?

Thanks!

Oh yeah sudo can break things. Ideally you should never run pip with sudo. I’m not entirely sure how to get out of that broken permission state once you’re in it.

However, if you ran trells init then you can run trellis exec pip install -r requirements.txt instead to make sure you’re in the activated virtualenv

edit: trellis init runs pip install automatically too

Ok so I took a chance and just sudo pip uninstall and then ran pip requirements from the new version of trellis and installed the new version of ansible fine.

I then did a deploy how I did before for an older trellis site and received the error I received yesterday… so I was back to where I wanted to be.

I then ran trellis deploy and received this:
Running command => ./bin/deploy.sh staging -----.com

PLAY [Ensure necessary variables are defined] **********************************

 **[WARNING]: Failure using method (v2_playbook_on_play_start) in callback plugin**

**(<ansible.plugins.callback./Users/----/Documents/projects/----/web**

**sites/trellis/lib/trellis/plugins/callback/vars.CallbackModule object at**

**0x7fc000267c50>): 'dict' object has no attribute 'iteritems'**

 **[WARNING]: You Ansible version is 2.7.13 but this version of Trellis has only**

**been tested for compatability with Ansible 2.4.0.0 -> 2.4.3.0. It is advisable**

**to check for Trellis updates or downgrade your Ansible version.**

TASK [Ensure environment is defined] *******************************************

 **[WARNING]: Failure using method (v2_runner_on_skipped) in callback plugin**

**(<ansible.plugins.callback.output.CallbackModule object at 0x7fc0086ebd68>):**

**name 'unicode' is not defined**

PLAY [Test Connection] *********************************************************

TASK [connection : Require manual definition of remote-user] *******************

TASK [connection : Specify preferred HostKeyAlgorithms for unknown hosts] ******

/bin/sh: grep: command not found

 **[WARNING]: Failure using method (v2_runner_on_failed) in callback plugin**

**(<ansible.plugins.callback.output.CallbackModule object at 0x7fc0086ebd68>):**

**name 'unicode' is not defined**

to retry, use: --limit @/Users/-----/Documents/projects/-----/websites/trellis/deploy.retry

PLAY RECAP *********************************************************************

------ : ok=0 changed=0 unreachable=0 failed=1

localhost : ok=0 changed=0 unreachable=0 failed=0

2019/10/02 15:30:15 exit status 2

Because it mentioned ansible 2.4.3.0, I downgraded in my projects requirements.txt and ran the trellis exec command you posted before. It downgraded fine.

When I ran deploy again, I received:

Running command => ./bin/deploy.sh staging ------.com

ERROR! Unexpected Exception, this is probably a bug: invalid syntax (__init__.py, line 96)

to see the full traceback, use -vvv

2019/10/02 15:36:12 exit status 250

I feel like we are close… any idea why neither ansible version is working?

Thanks again!

Just wanted to summarize here for easier reading.

So If I do a full install of ansible 2.7.5, this trellis site deploys fine. If I upgrade, it stops working.

If I use trellis cli and requirements.txt with ansible==2.7.5 and passlib, I get further but also receive the errors above.

Maybe I need to put more in the requirements.txt? There is needed functionality missing in the virtualenv?

Thanks!

virtualenv python version is 3.7 and outside of it is 2.7.15.

That probably the prob?

Should I put python==2.7.15 in requirements.txt as well?

Ok, it looks like a virtualenv needs to be created with the wanted python version in the command. I guess I have python 3 installed on here but 2 is still the default version but trellis-cli ound 3 and used 3.

How can I make trellis-cli create a virtualenv with python 2.7 without deleting python 3?

Thanks again!

Unfortunately not yet. It defaults to python3 if installed. Although the Python version itself shouldn’t really matter :thinking:

Ok, it looks like a virtualenv needs to be created with the wanted python version in the command.

I’m not sure what command you mean. Is it running deploy? If so, you should use trellis-cli’s deploy command. I wasn’t really clear on this, but if you’re trying to use it’s built-in venv feature, then all commands should be run through it as well.

It has almost every common command built-in and for those that aren’t, you can run anything through trellis exec <anything>.

So in theory just using trellis-cli should make everything work without having to care about python version, ansible, etc.

Yep I am running trellis-cli’s deploy and getting the errors above.

I looked into ‘dict’ object has no attribute ‘iteritems’** and name ‘unicode’ is not defined* and it seems that these commands are in python 2 but not 3.

I checked python version on my mac with python --version and got 2.7.15 and when I use trellis exec python --version I get 3.7.0

I’m thinking that could be the issue?

Did the python version that trellis uses change in the last year to year and a half?

Thanks!

Also, from reading your latest reply, it is possible you only saw my last response… i had written a few as I found new things in my research… so you can see the error messages and extra info above when you have the time… and really thanks a lot for helping me get through it.

Did the python version that trellis uses change in the last year to year and a half?

Okay yeah this makes sense, sorry. I think I assumed your projects couldn’t be that old :slightly_frowning_face: Definitely looks like they are old enough not to have the Python 3 support we’ve added over time. For a while now Trellis supports both versions.

Sorry I’ve led you down a bit of a rabbit-hole then without asking some initial questions. Let me add an option to specify the python used for init quickly. I’ll push a new version tonight hopefully.

In the meantime you can always try to get pip working as usual without trellis-cli

; ) Yeah the one I was deploying to was probably created June-Aug 18. I never updated these projects because they always worked and didn’t want to break anything.

Thank you very much for being so responsive on this and please don’t go crazy trying to fix anything too fast. I can always upgrade and downgrade as needed if I have to work on any new projects or mess with virtualenv myself and that post I linked to in my initial post.

And also glad you pointed me to trellis-cli which is going to make my life so much easier for new projects and also to manage my older projects and virtual environments… freakin awesome that you created it!

Josh

1 Like

I did take a look at this last night but of course it wasn’t as easy as I originally thought :pensive: I need to think about it a bit more.

Thanks for trying out trellis-cli!

Yeah, it’s never as quick/easy as we think sadly.

I’m watching the project now and let me know if I can help in any way.

Thanks!