No module named packaging.version for Ansible VM provisioning in Azure - python-2.7

I am using a CentOS 7.2 and trying to provision a VM in azure through Ansible using the module "azure_rm_virtualmachine" and getting the error as "No module named packaging.version" Below is my error
Traceback (most recent call last):
File "/tmp/ansible_7aeFMQ/ansible_module_azure_rm_virtualmachine.py", line 445, in
from ansible.module_utils.azure_rm_common import *
File "/tmp/ansible_7aeFMQ/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 29, in
ImportError: No module named packaging.version
fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_7aeFMQ/ansible_module_azure_rm_virtualmachine.py\", line 445, in \n from ansible.module_utils.azure_rm_common import *\n File \"/tmp/ansible_7aeFMQ/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 29, in \nImportError: No module named packaging.version\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}
Below is my playbook and I am using a ansible version 2.3.0.0 and python version of 2.7.5 and pip 9.0.1
name: Provision new VM in azure
hosts: localhost
connection: local
tasks:
name: Create VM
azure_rm_virtualmachine:
resource_group: xyz
name: ScriptVM
vm_size: Standard_D1
admin_username: xxxx
admin_password: xxxx
image:
offer: CentOS
publisher: Rogue Wave Software
sku: '7.2'
version: latest
I am running the playbook from the ansible host and I tried to create a resource group through ansible but I get the same error as "No module named packaging.version" .

The above error is occurred due to your environment doesn't have packaging module.
To solve this issue by installing packaging module.
pip install packaging
The above command will install packaging module of 16.8 version

You may try this, it solved for me
sudo pip install -U pip setuptools
FYI: My ENVs are
Ubuntu 16.04.2 LTS on Windows Subsystem for Linux (Windows 10 bash)
Python 2.7.12
pip 9.0.1
ansible 2.3.1.0
azure-cli (2.0.12)

Related

Docker-compose wouldn't start on Sagemaker's Notebook instance

Docker-compose seems to have stopped working on Sagemaker Notebook instances. When running docker-compose up I encounter the following error:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin/docker-compose", line 8, in <module>
sys.exit(main())
File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/compose/cli/main.py", line 81, in main
command_func()
File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/compose/cli/main.py", line 200, in perform_command
project = project_from_options('.', options)
File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/compose/cli/command.py", line 70, in project_from_options
enabled_profiles=get_profiles_from_options(options, environment)
File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/compose/cli/command.py", line 153, in get_project
verbose=verbose, version=api_version, context=context, environment=environment
File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/compose/cli/docker_client.py", line 43, in get_client
environment=environment, tls_version=get_tls_version(environment)
File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/compose/cli/docker_client.py", line 170, in docker_client
client = APIClient(use_ssh_client=not use_paramiko_ssh, **kwargs)
File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/docker/api/client.py", line 197, in __init__
self._version = self._retrieve_server_version()
File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.6/site-packages/docker/api/client.py", line 222, in _retrieve_server_version
'Error while fetching server API version: {0}'.format(e)
docker.errors.DockerException: Error while fetching server API version: Timeout value connect was Timeout(connect=60, read=60, total=None), but it must be an int, float or None
I can start Docker containers as usual.
sh-4.2$ docker version
Client:
Version: 20.10.7
API version: 1.41
Go version: go1.15.14
Git commit: f0df350
Built: Tue Sep 28 19:55:40 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.15.14
Git commit: b0f5bc3
Built: Tue Sep 28 19:57:35 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.6
GitCommit: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc:
Version: 1.0.0
GitCommit: %runc_commit
docker-init:
Version: 0.19.0
GitCommit: de40ad0
But docker-compose wouldn't work...
sh-4.2$ docker-compose version
docker-compose version 1.29.2, build unknown
docker-py version: 5.0.0
CPython version: 3.6.13
OpenSSL version: OpenSSL 1.1.1l 24 Aug 2021
For those of you who (might) have encountered the same issue, here's the fix:
1). Install the newest version of docker-compose:
sh-4.2$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sh-4.2$ sudo chmod +x /usr/local/bin/docker-compose
2). Change your PATH accordingly (since docker-compose is installed using conda and is picked up first) or use /usr/local/bin/docker-compose onwards:
sh-4.2$ PATH=/usr/local/bin:$PATH
sh-4.2$ docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
Perhaps, the issue is related to this:
On August 9, 2021 the Jupyter Notebook and Jupyter Lab open source software projects announced 2 security concerns that could impact Amazon Sagemaker Notebook Instance customers.
Sagemaker has deployed updates to address these concerns, and we recommend customers with existing notebook sessions to stop and restart their notebook instance(s) to benefit from these updates. Notebook instances launched after August 10, 2021, when updates were deployed, are not impacted by this issue and do not need to be restarted.

how to install the ssl module for python 2.7.17 on opensuse (SLES) 15 SP2?

I have installed OpenSSL and python2-pyOpenSSL-17.5.0-lp152.6.2.noarch.rpm in my SLES machine and still, I am getting the following error:
import ssl inside python CLI
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named ssl
pip install numpy gives the following error:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Can anyone help me with this?
You may need to install libopenssl-devel package

AWSEBCLI does not work when running on Jenkins. No module named ERROR

I'm working on a continuous deployment for an application at work using Jenkins with Multibranch Pipeline, AWSCLI and AWSEBCLI. When running via ssh, everything works fine, but on jenkins don't.
Application:
- Java 8
- Maven
- Quarkus Framework https://quarkus.io/
Jenkinsfile:
tools {
jdk 'jdk_1.8.0'
maven 'Maven'
}
stages {
stage('Environment Configuration') {
steps {
sh 'sudo pip install awscli==1.16.9 awsebcli==3.14.4'
}
stage('Deploy') {
when {
anyOf {
branch 'feature/CD'
}
}
steps {
sh 'zip -r application.zip target Dockerfile'
sh 'aws configure set aws_access_key_id $ACCESS_KEY_DEV --profile eb-cli'
sh 'aws configure set aws_secret_access_key $SECRET_KEY_DEV --profile eb-cli'
sh 'eb deploy'
}
}
}
}
On SSH:
[root]# eb --version
EB CLI 3.14.4 (Python 2.7.5)
[root]# python --version
Python 2.7.5
[root]# aws --version
aws-cli/1.16.9 Python/2.7.5 Linux/3.10.0-862.11.6.el7.x86_64 botocore/1.11.9
[root]# eb deploy
Uploading application/app-9d9c-191122_104206.zip to S3. This may take a while.
Upload Complete.
2019-11-22 13:42:09 INFO Environment update is starting.
2019-11-22 13:42:13 INFO Deploying new version to instance(s).
On Jenkins:
+ python --version
Python 2.7.5
[Pipeline] sh
+ aws --version
aws-cli/1.16.9 Python/2.7.5 Linux/3.10.0-862.11.6.el7.x86_64 botocore/1.11.9
+ eb deploy
Traceback (most recent call last):
File "/bin/eb", line 5, in <module>
from ebcli.core.ebcore import main
File "/usr/lib/python2.7/site-packages/ebcli/core/ebcore.py", line 21, in <module>
from ebcli.controllers.clone import CloneController
File "/usr/lib/python2.7/site-packages/ebcli/controllers/clone.py", line 17, in <module>
from ..operations import cloneops, commonops, solution_stack_ops
File "/usr/lib/python2.7/site-packages/ebcli/operations/solution_stack_ops.py", line 23, in <module>
from ebcli.operations import commonops, platformops
File "/usr/lib/python2.7/site-packages/ebcli/operations/platformops.py", line 22, in <module>
from semantic_version import Version
ImportError: No module named semantic_version
You probably have multiple pips on your computer. pip install awsebcli is supposed to have installed the semantic_version Python package, however, as you can see from the stack trace you have posted, it couldn't be found. To get around these problems, you should ideally use virtualenv. If you just want a clean installation, Beanstalk provides a set of scripts for you to install EBCLI without any friction.

'ModuleNotFoundError: No module named 'MySQLdb' In Django

creating my first module in django,
I am using mac Tried steps:
1.installed python 3.6.+ version,
2.cloned git project
3.setup local env,
to create a module,
trying with command
env=dev python3 manage.py startapp supriya_module_inflow;
getting error in console :
Environment Selected :dev
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 24, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 35, in <module>
execute_from_command_line(sys.argv)......
...
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
MySQLdb does not support Python 3. You'll want to pick one of the other MySQL drivers.
At the time of writing, the latest release of MySQLdb (1.2.5) doesn’t support Python 3. In order to use MySQLdb under Python 3, you’ll have to install mysqlclient instead.
Here is How to install mysqlclient in Python using pip so as to be able to import MySQLdb in Django 3.1 when running Python 3.8.5..
The error message indicates that there is no module named MySQLdb. It means, Python needs a module to interface with MySQL database and that modules does not seems to be present in the system. All you need to do is, just install MySQL-Python module and the script should work without any problem.
Using Python Pip
pip install MySQL-python
Collecting MySQL-python
Installing collected packages: MySQL-python
Running setup.py install for MySQL-python
Successfully installed MySQL-python-1.2.5
On Ubuntu based systems
# apt-get install python-mysqldb
On RHEL/CentOS based systems:
# yum install MySQL-python
Using easy_install
# easy_install mysql-python
If you are on a virtual environment then
pip install MySQL-python
You can also check this related issue.
** Building wheel for MySQL-python (setup.py) ... error
ERROR: Command errored out with exit status 1:**
can't able to install MySQL-python and getting the above error .

ansible - python lxml issue with maven_artifact module

I have ansible (v2.0.0.2) and python (v2.7.6) and i'm running the 'maven_artifact' module.
As a direct ansible command, it works fine
ansible localhost -m maven_artifact -a "group_id=commons-collections artifact_id=commons-collections dest=/tmp/commons-collections-latest.jar" -vvvv
but when i do the same via a playbook
- name: download via maven
maven_artifact: group_id=junit artifact_id=junit dest=/tmp/junit-latest.jar
it fails with this error
fatal: [test01vm1]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "maven_artifact"},
"module_stderr": "",
"module_stdout": "\r\nTraceback (most recent call last):\r\n
File \"/home/admin123/.ansible/tmp/ansible-tmp-1454675562.75-201853614879442/maven_artifact\",
line 25, in <module>\r\n from lxml import etree\r\nImportError:
No module named lxml\r\n", "msg": "MODULE FAILURE", "parsed": false}
I believe might be related to the python lxml module, and i found these existing tickets
http://stackoverflow.com/questions/13355984/get-errors-when-import-lxml-etree-to-python
http://stackoverflow.com/questions/4598229/installing-lxml-module-in-python
I'm wondering might someone have a workaround for this?
EDIT - Add python path details
I ran this command to see what path's are on the python home
14:55:11#pcZBook-15:/usr/local/etc$ python -c 'import sys; print(":".join(sys.path))'
The list of folders is
:/opt/stack/keystone
:/opt/stack/glance
:/opt/stack/cinder
:/opt/stack/nova
:/opt/stack/horizon
:/usr/lib/python2.7
:/usr/lib/python2.7/plat-x86_64-linux-gnu
:/usr/lib/python2.7/lib-tk
:/usr/lib/python2.7/lib-old
:/usr/lib/python2.7/lib-dynload
:/usr/local/lib/python2.7/dist-packages
:/usr/lib/python2.7/dist-packages
:/usr/lib/python2.7/dist-packages/PILcompat
:/usr/lib/python2.7/dist-packages/gtk-2.0
:/usr/lib/pymodules/python2.7
:/usr/lib/python2.7/dist-packages/ubuntu-sso-client
:/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode
It seems that ansible was trying to execute the 'maven_artifact' command on the remote target host, which didn't have the required python libraries.
In my case I only wanted to run the command on the local 'ansible_host' so I just added the 'local_action' prefix and the command runs.
- name: download via maven
local_action: maven_artifact group_id=junit artifact_id=junit dest=/tmp/junit-latest.jar
What I usually do is to call:
- name: Install PIP
apt: name=python-pip state=present
- name: Install lxml
pip: name=lxml
Just do
sudo apt-get install python-lxml
You need to install lxml in [test01vm1].
pip install lxml
Verify that target machine has python lxml module, and ansible selects the python interpreter where you have installed the lxml module.
[ec2-user#i-05f345345aas6b bin]$ pip list | grep xml
lxml 3.2.1
And then double check that ansible picks that python version by adding:
ansible_python_interpreter=/usr/bin/python2
See https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html
I have observed that ansible 2.12 ansible picks python3 interpreter by default, if no python interpreter is defined in target machine. So double check with
pip3 list | grep lxml
that lxml module is also available for python3