Version of Python when running Ansible commands - macos

I am using OSX.10.12.6.
I installed ansible via pip3 (in order to use it with Python3 considering Python2 is already installed on my machine by default) and downloaded the ec2.py external inventory script from Ansible github
But when running ansible commands, I get the error:
[WARNING]: * Failed to parse
~/ec2.py with script plugin: Inventory script
~/ec2.py) had an execution error: Traceback (most recent call last): File
"~/ec2.py", line 130, in <module> import boto ImportError: No module named boto
It seems to be because ansible is using Python2 instead of Python3 (I checked, I cannot import boto or ansible from Python2 but I can from Python3). Also I can run successfully the following python3 ec2.py
What is surprising is that if I run ansible --version, I get the following:
ansible 2.8.3
config file = ~/ansible.cfg
configured module search path = ['/Users/XXXX/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.6.5 (default, Mar 30 2018, 06:42:10) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
Is there anything I can do to "force" ansible to use Python3 instead of Python2?
PS: Note that I can get through the initial error by pip install boto on Python2, but others error pop up and would rather use Python3

FreeBSD Quarterly (Stable) Ports Branch released today 2019Q3 has Ansible 2.7.10. HEAD upgraded to Ansible 2.8.3 last Sunday! The conclusion is, FreeBSD decided not to put 2.8.3 into the STABLE branch. Probably one of the reasons is the new feature in Ansible 2.8 Python interpreter discovery. See Using FLAVORS. Hence either you downgrade to Ansible 2.7, or you proceed with fixing the HEAD (in MacOS).
It might be worth to try and set ansible_python_interpreter to Python 2.7.
(Some might argue it's rather a comment. I started there, but it's too long.)

Related

Ansible 2.9.7 on RHEL 7.9 - Upgrade plan

Ansible 2.9.7 is running on RHEL 7.9 server.
We are planning to upgrade the Ansible to latest version.
As per documentation, there are many Ansible versions released after 2.9.7 and latest one is Ansible 7 (ansible-core and ansible).
Can you advise which version would be the appropriate one to upgrade from 2.9.7 on the existing RHEL 7.9 server ? Does latest Ansible versions support RHEL 7.9 ?
Can you advise which version would be the appropriate one to upgrade from 2.9.7 on the existing RHEL 7.9 server?
This will depend on your environment and capabilities.
... just like to note that within Enterprise Packages for Linux (EPEL) a version with bug fixes is available, Ansible v2.9.27.
~/test$ yum provides ansible
...
ansible-2.9.27-1.el7.noarch : SSH-based configuration management, deployment, and task execution system
Repo : EPEL-7
Does latest Ansible versions support RHEL 7.9?
Since it is written in Python it is somehow agnostic about the underlying OS, but it will depend on the Python version installed.
If you don't plan to install another Python environment and stay with the distributed version from the OS, Python 2.7, then you are bound up to Ansible v2.11. See Ansible Community Topic Issue #54.
~/test$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.9 (Maipo)
~/test$ ansible --version
ansible [core 2.11.12]
config file = /home/user/test/ansible.cfg
configured module search path = [u'/home/user/.ansible/plugins/modules', u'/home/user/.ansible/collections/ansible_collections']
ansible python module location = /home/user/.local/lib/python2.7/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /home/user/.local/bin/ansible
python version = 2.7.5 (default, May 27 2022, 11:27:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
jinja version = 2.11.3
libyaml = True
If you can install another Python environment you can use higher Ansible versions.
Please take note that certain modules, Ansible Galaxy, Collections, etc. may have own requirements and dependencies.
Further Documentation Links
Installing Ansible - Prerequisites (v2.9)
Installing Ansible - Requirements (latest)
Releases and maintenance (latest)

What Ansible version does AWX 19.1.0 offer?

I am using AWX 17.1.0 which offers Ansible version 2.9.18. The older Ansible version is becoming a bit of an issue. There does not seem to be a documented way to upgrade Ansible in an existing Ansible installation. I am using btw a local docker setup.
Is this correct? That there is no documented / approved way to update Ansible?
Local docker I think is no longer an option so there is also no way to upgrade my AWX to 19.1.0.
On the website I cannot find any information on the Ansible version of AWX 19.1.0. What is Ansible version of AWX 19.1.0?
Is this correct? That there is no documented / approved way to update Ansible?
Yes. Meanwhile I have done it by building my own custom image and it worked at the time (at least for our team usage). But it is clearly not recommended. (Note that the way the images are built has drastically changed since I have done this)
Local docker I think is no longer an option so there is also no way to upgrade my AWX to 19.1.0.
I made the same interpretation mistake as you and that is actually a wrong statement. This install type just doesn't have the same visibility in the current documentation (a simple link on the install page) and has been moved to a separate page
I cannot find any information on the Ansible version of AWX 19.1.0
I didn't either briefly looking at the code, but the easiest way is probably to spawn a test install and try.
sh-4.4$ ansible --version
ansible [core 2.11.0rc2]
config file = None
configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.8.3 (default, Aug 31 2020, 16:03:14) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
jinja version = 2.10.3
libyaml = True

Cannot run yum due to libssl.so.10: cannot open shared object file: No such file or directory

I inadvertently ran the following command in AWS EC2 Lightsail instance
rpm --nodeps -e openssl-1.0.2k-16.150.amzn1.x86_64
and ever since I am unable to run any yum commands
[root#ip-172-26-3-161 abc]# yum update
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
libssl.so.10: cannot open shared object file: No such file or directory
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.16 (default, Oct 14 2019, 21:26:56)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
Any pointers on how to recover from this
You should find the original version of openssl, download it from amazon repo and install it with rpm command. And next time use command yum localinstall ... to install local packages.

Ansible: path to ansible.cfg

I have this known issue. So I try to fix it but I don't see where I have to create my ansible.cfg (or does it already exist)? I tried it in my homedirectory but it still did not work.
sudo vi ~/.ansible.cfg
I read a lot about /etc/ansible but on my system it isn't there.
I'm on Mac El Capitan. I've installed ansible by using pip.
ansible --version
ansible 1.9.4
configured module search path = None
From the docs:
Changes can be made and used in a configuration file which will be processed in the following order:
ANSIBLE_CONFIG (an environment variable)
ansible.cfg (in the current directory)
.ansible.cfg (in the home directory)
/etc/ansible/ansible.cfg
I'm not sure this does 100% apply to 1.9.4. Ansible is terrible in versioning their documentation. (=there only is one version and not always the version a feature was introduced or changed is mentioned)
But I am sure everything except ~/.ansible.cfg works in 1.x as I have tried that before.
So if you have created ~/.ansible.cfg and it is not being used, check if the environment var ANSIBLE_CONFIG is set or there is one file in the directory from where you call ansible. The first one found will be used. processed in the following order does not mean they will be merged in that order. First one found wins.
I read a lot about /etc/ansible but on my system it isn't there.
Yeah, that depends on how Ansible was installed. If it's not there you could just create it but if you do not need it, no need to create it. I actually deleted mine as I see no use for it.
For latest version (2.7.6) if you install via pip you wont get ansible folder in /etc.
so this is what you get when you do ansible --version
ansible --version
ansible 2.7.6
config file = None
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
But once you manually create directory under /etc as ansible and add ansible.cfg file there ansible automatically detects it. but you will have to configure the rest manually like hosts file..etc . so after this we get
ansible --version
ansible 2.7.6
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
I got the same thing when I used pip. But I think better way is either using apt or yum according to your OS.
I have centOS so following worked for me.
To get Ansible for CentOS 7, first ensure that the CentOS 7 EPEL repository is installed:
sudo yum install epel-release
Once the repository is installed, install Ansible with yum:
sudo yum install ansible
We now have all of the software required to administer our servers through Ansible.
Reference: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-centos-7

cassandra 2.2 CQl Shell supports python 2.7

Error I am get when trying to start cql Shell
>cqlsh
CQL Shell supports only Python 2.7
>
I have installed python2.7 but it is still giving the same error.
do i have to set path some were?
i have installed Cassandra 2.2 from datastax suing this command
sudo yum install dsc22
Depending on your distribution and its version you cannot change the default python version of the system without breaking the system. If you have Python 2.7 installed then its interpreter is probably on your path as python2.7.
Try running python2.7 --version. If that gives you an output like Python 2.7.x you are good. Just edit the cqlsh script and replace python with python2.7 at the beginning of the only code line in the file.
You should use python 2.7 but be aware of https://issues.apache.org/jira/browse/CASSANDRA-11850
Not enough rep to post as a comment. If you encounter same problem as #andrewdeal and you installed Python 2.7 side-by-side (a must on CentOS 6 which requires Python 2.6), you need site-packages in your Python 2.7 install.
As root:
rm /usr/local/lib/python2.7/site-packages/README
rmdir /usr/local/lib/python2.7/site-packages
ln -s /usr/lib/python2.7/site-packages/ /usr/local/lib/python2.7
You can now run cqlsh
I tried doing that change from python to python2.7 and then got:
Traceback (most recent call last):
File "/usr/bin/cqlsh.py", line 152, in <module>
from cqlshlib import cql3handling, cqlhandling, pylexotron, sslhandling
ImportError: No module named cqlshlib

Resources