Ansible DistributionNotFound jinja2 - ansible

When I run the following ansible command
ansible webservers -m ping
It reports "DistributionNotFound jinja2<2.9". I then updated jinja to 2.9.4 :
pip install --upgrade jinja2
But ansible still reports the same error when running it. Does anybody can help? Thanks!

I eventually figured out the solution, which is to update distribute rather than jinja2. Then reinstall ansible (my ansible was initially installed via pip):
pip install -U distribute
pip uninstall ansible
pip install ansible
Thanks to #KonstantinSuvorov and #techraf for your help.

Related

Unable to locate ansible after installing on MacOS

Installed ansible using pip on my macOS running Mojave (10.14.6)
pip install --user ansible
After running I got a successful installation
Successfully installed MarkupSafe-1.1.1 PyYAML-5.1.2 ansible-2.8.5 asn1crypto-1.0.1 cffi-1.12.3 cryptography-2.7 enum34-1.1.6 ipaddress-1.0.22 jinja2-2.10.3 pycparser-2.19
Running my first command
Macbook:~ t0o0tz$ ansible --version
-bash: ansible: command not found
Locate yielded no results. I ran an upgrade and received a bunch of:
Requirement already satisfied, skipping upgrade
During the upgrade I also got a location for ansible
ansible in /Users/t0o0tz/Library/Python/2.7/lib/python/site-packages (2.8.5)
But could not find ansible in 'site-packages'
site-packages contents below:
Extras.pth easy-install.pth vboxapi
README pip-19.2.3-py2.7.egg vboxapi-1.0-py2.7.egg-info
Am I missing something?
The executable file was located in $HOME/Library/Python/2.7/bin
./ansible --version
ansible 2.8.5
Thanks Matthew L Daniel!

Ansible: Unable to run docker compose in an ansible playbook

I appear to be unable to run docker compose tasks in an ansible playbook. I get stuck in a loop.
The first error I get when running sudo ansible-playbook playbook.yml is the following
fatal: [10.0.3.5]: FAILED! => {"changed": false, "msg": "Unable to load docker-compose. Try `pip install docker-compose`. Error: No module named compose"}
so I remote to that machine and did sudo pip install docker-compose and try running the playbook again. This time I get...
fatal: [10.0.3.5]: FAILED! => {"changed": false, "msg": "Cannot have both the docker-py and docker python modules installed together as they use the same namespace and cause a corrupt installation. Please uninstall both packages, and re-install only the docker-py or docker python module"}
so I try uninstalling docker python...
sudo uninstall docker python
Then I get the following when attempting to run the playbook again
fatal: [10.0.3.5]: FAILED! => {"changed": false, "msg": "Failed to import docker-py - No module named docker. Try `pip install docker-py`"}
However this is already install on the machine, as when I run sudo pip install docker-py I see the following...
Requirement already satisfied (use --upgrade to upgrade): docker-py in /usr/local/lib/python2.7/dist-packages
Cleaning up...
Does anyone know how to escape this loop and successfully get an ansible playbook that uses docker-compose to run?
The machine os is linux 14.04
Thanks,
What worked for me was to first uninstall everything docker related in the virtualenv for Ansible.
pip uninstall docker docker-py docker-compose
And then install the docker-compose module, which will install the docker module as well as a dependency.
pip install docker-compose
The Ansible docker module will try to import docker, which will also succeed with the docker module, and as such not provide an error with the misleading instruction to install docker-py.
I had the just had the same error message while trying to run sudo ansible playbook-with-docker.yaml
{"changed": false, "msg": "Unable to load docker-compose. Try `pip install docker-compose`. Error: No module named compose"}
I took me about 2 hours to figure out that in Linux pip install is not the same as sudo pip install (quite obvious, once you know what's happening ).
So in case someone has the same issue - make sure you're you are running everything consistently either as sudo or not sudo, but don't mix stuff :)
...and use sudo pip list | grep docker to verify.
As already stated in other answers, docker-compose python module is missing.
You can install it manually as previous answers indicate or you can use a "pure" Ansible solution that is to install via a task.
For that, use ansible.builtin.pip to install docker-compose module (you can add more modules to install if needed in the same task).
- hosts: all
gather_facts: no
tasks:
- name: Install docker-compose python package
ansible.builtin.pip:
name: docker-compose
Reference: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/pip_module.html
To add more context to Thermostat's answer
I was using pip3 and not pip with the following:
Ubuntu 20.04
Ansible 2.10.7
Python 3.8.10
pip 20.0.2 (pip3)
Here's how I fixed mine:
So first I ran the command to remove all existing copies of docker, docker-py and docker-compose python libraries:
pip3 uninstall docker docker-py docker-compose
And then ran the command below to install the python docker-compose library alongside the python docker library
pip3 install docker-compose
That's all.

How to downgrade and install ansible 1.9.4 on a mac

So due to some strict versioning requirements I need to downgrade my version of Ansible from 2.1.1.0 to 1.9.4
How can I do this (preferably with brew)?
If not with brew, then this may be an option. Otherwise I have heard that using virtual env may also be a good option so that I can easily run version 2.1.1.0 or 1.9.4 similar to the manner in which rbenv works.
I vote for virtualenv. But if you want to install ansible 1.9:
$> brew uninstall ansible
$> brew search ansible
ansible
ansible#1.9
ansible#2.0
...
$> brew install ansible#1.9
$> pip remove ansible
$> pip install ansible==1.9.4
$> ansible --version
ansible 1.9.4
configured module search path = None
If you use pip, you can use
pip install ansible==<version-number>
This will uninstall old version and install the new one.
This logs are from my local machine when I downgraded my version from 2.7.4 to 2.4.2
Installing collected packages: ansible
Found existing installation: ansible 2.7.4
Uninstalling ansible-2.7.4:
Successfully uninstalled ansible-2.7.4
Running setup.py install for ansible ... done
Successfully installed ansible-2.4.2.0
If you installed ansible with pip, the use the following command.
pip uninstall ansible
NOTE after you use it still possible to run ansible and get the help commands which shows that it is not uninstalled properly. See https://github.com/ansible/ansible/issues/46337.
Required to execute the command as root.

Yum Update ansible version

I have ansible version 1.9 on my Centos 7 machine, but need to get version 1.9.2 as I'm running into compatibility issues with ansible and docker.
However, doing a yum update on the ansible package has no affect:
yum update -y ansible
No packages marked for update
How can I upgrade the package?
Edit:
I have upgraded the package using pip as suggested by #Eldad AK:
sudo pip install --upgrade ansible==1.9.2
And the upgrade appeared to be successful:
Successfully installed MarkupSafe-0.23 ansible-1.9.2 ecdsa-0.13 jinja2-2.8 paramiko-1.16.0 setuptools-20.7.0
However when i run the ansible executable and check the version, it's still at 1.9:
ansible --version
ansible 1.9 (devel affb66416f) last updated 2015/11/04 09:09:40 (GMT +100)
You can upgrade it using pip. Try
sudo pip install --upgrade ansible
This is how we update Ansible.
I hope this helps.
You probably have two versions of ansible installed:
1.9 installed via yum. Which is the one in your path and probably in /usr/bin/ansible.
1.9.2 installed via pip. Check /usr/lib/python-version/site-packages/, I guess there is an ansible-1.9.2-* directory there.
You can either uninstall the first one or include the second one in you PATH with a higher precedence.
A quick and dirty fix would be:
mv /usr/bin/ansible /usr/bin/ansible1.9 && mv /usr/bin/ansible-playbook /usr/bin/ansible-playbook1.9
ln -s /usr/lib/python-<version>/ansible-1.9.2-py[...].egg/EGG/scripts/ansible /usr/bin/ansible
ln -s /usr/lib/python-<version>/ansible-1.9.2-py[...].egg/EGG/scripts/ansible-playbook /usr/bin/ansible-playbook
sudo python -m pip uninstall ansible
sudo python -m pip install ansible

Updating Ansible version using "sudo pip install ansible --upgrade" does not update the core modules

I used sudo pip install ansible --upgrade to upgrade Ansible on CentOS 6. When I typed ansible --version, it gave me the updated version number. However all the Ansible core modules did not get updated. I had to manually update the core modules one by one from the source.
Does anyone know how to do Ansible version update with all the core modules being updated as well?
I guess it has something todo with Ansible recently (I think around 1.7.x) being split up from one github repo into 3 separate github repos. Ansible core and Ansible modules not in the same repository any longer.
How did you install Ansible in the first place? Did you use pip install <ansible-repo>? Then that might be the problem. The docs say to use easy_install with pip. If you did that, maybe still just pip uninstall it and re-install.
Also, there is a rpm to use with yum on CentOS. (which I use and did not have problems updating)

Resources