It seems easy_install3 is not currently available as an ansible module. So instead of doing this:
---
- name: Install apt dependencies
apt: name={{item}} state=installed
with_items:
- python3-setuptools
- name: install pip3
easy_install3: name=pip
I'm using this:
---
- name: Install apt dependencies
apt: name={{item}} state=installed
with_items:
- python3-setuptools
- name: install pip3
shell: easy_install3 pip
Is there a better alternative?
As mentioned in the comments, you can just use apt to install python3-pip rather than going via easy_install like the dark old days:
---
- name: Install apt dependencies
apt: name=python3-pip state=installed
If you did need to force a specific executable for easy_install then you could use the executable option:
- name: install pip3
easy_install: name=pip
executable: easy_install-3.3
However, it might also help to know that pip has been bundled with Python since 3.4 so you might not need to do anything at all.
I think executable option can be used to mention the version of easy_install. However(as suggested in the comments), it is recommended to use the pip module which you can first install using easy_install.
See: http://docs.ansible.com/ansible/easy_install_module.html for more information.
Related
I'm currently working with a centos5 host and I have to install some packages with yum.. unfortunately, as far as I know, centos5 doesn't support Ansible's yum module so I have to use the 'command' or 'shell' modules and 'hard code' everything by myself.
My question is.. what are the conditions I should implement to make a command/shell behave like Ansible's yum module and make it as much 'indepotent' as possible?
For the moment this is what I came up with:
When installing/updating a package
- name: INSTALL (C5) - Install package
ansible.builtin.command:
cmd: yum -y install <package>
register: output_install
changed_when: '"Installing:" in output_install["stdout"] or "Updating:" in output_install["stdout"]'
failed_when: output_install["stdout"] is regex("No package.*available")
When removing a package
- name: UNINSTALL (C5) - Remove package
ansible.builtin.command:
cmd: yum -y remove <package>
register: output_remove
changed_when: '"Erasing" in output_remove["stdout"]
failed_when: "No Packages marked for removal" in output_remove["stdout"]'
Do you guys have any suggestion or have already dealt with this problem?
Thank you very much.
At first, I'm trying to install Qt with apt-get install qtchooser libgl-dev qt5-default qttools5-dev-tools python3.6 qtwebengine5-dev.
However, this install a Qt version of 5.9.
And I have tried to install Qt by using
sudo wget http://download.qt.io/official_releases/qt/5.13/5.13.1/qt-opensource-linux-x64-5.13.1.run;
sudo chmod +x ./qt-opensource-linux-x64-5.13.1.run;
sudo ./qt-opensource-linux-x64-5.13.1.run;
And this gave another error:
QStandardPaths: wrong ownership on runtime directory /run/user/2000, 2000 instead of 0
qt.qpa.screen: QXcbConnection: Could not connect to display
Could not connect to any X display
What is the proper solution to install Qt 5.13 on travis-ci linux?
Based on two people's answer(thank you very much), I have update my .travis.yml like this:
addons:
apt:
sources:
- sourceline: 'ppa:beineri/opt-qt-5.13.2-bionic'
packages:
- qt513base
- qt513tools
- qt513webengine
- qt513x11extras
- qt513translations
- qt513scxml
- qt513script
However, another error appear:
ome packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
qt513webengine:i386 : Depends: qt513base:i386 but it is not going to be installed
Depends: qt513declarative:i386 but it is not going to be installed
Depends: qt513location:i386 but it is not going to be installed
Depends: qt513quickcontrols2:i386 but it is not going to be installed
Depends: qt513webchannel:i386 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
How to solve that?
I could use some of the alternatives shown in the answers to question Silent install Qt run installer on ubuntu server.
In this case I see that the simplest solution is to use qtci:
language: generic
dist: bionic
addons:
apt:
packages:
- libxkbcommon-x11-0
- libgl1-mesa-dev
services:
- xvfb
env:
- QT_CI_PACKAGES=qt.qt5.5132.gcc_64,qt.qt5.5132.qtwebengine PATH="$TRAVIS_BUILD_DIR/Qt/5.13.2/gcc_64/bin:${PATH}"
script:
- git clone https://github.com/benlau/qtci.git
- source qtci/path.env
- install-qt 5.13.2
In this project I use the previous script to run an example of Qt.
You can use one of Stephan Binner's launchpad repositories containing builds of recent Qt versions.
For example, if you want to use Qt 5.13.1, you can write the following in your .travis.yml's install section (assuming you use xenial build image):
sudo apt-add-repository -y ppa:beineri/opt-qt-5.12.1-xenial &&
travis_wait 30 sudo apt-get -qq update &&
sudo apt-get -qq install qt512tools qt512base &&
source /opt/qt512/bin/qt512-env.sh
Add other Qt packages as you need.
Also a note on one of the errors you see: the one about not being able to connect to any X display. If whatever you want to run on Travis CI normally requires GUI to run, you can use xvfb to work around this issue: for this to work you need to add the following to the top level of your .travis.yml:
services:
- xvfb
Try to add the ppa manually in your travis configuration:
- os: linux
dist: bionic
sudo: require
addons:
apt:
sources:
- sourceline: 'ppa:beineri/opt-qt-5.13.2-bionic'
packages:
- qt513base
I am learning ansible.
I want to install virtual environment and install cassandra-driver inside venv. Could some one suggest me how to do that?
here is the code I have tried.
- hosts: localhost
gather_facts: no
connection: local
name: install cassendra-driver
become: true
become_user: root
tasks:
- name: Install the latest version of pip
apt:
name: python-pip
state: latest
force_apt_get: yes
- name: Install virtualenv
pip:
name:
- virtualenv
- name: Install "cassandra-driver"
pip:
name:
- cassandra-driver==3.19.0
Please help me..
There are two issues with your playbook:
you are installing pip and cassandra-driver on your local machine but you are trying to install them inside a virtual environment
virtual environenments already contain pip so you don't need to install it
This should fix your issues:
tasks:
- name: Manually create the initial virtualenv
command: python3 -m venv env
- name: Install "cassandra-driver"
command: env/bin/python -m pip install cassandra-driver
I am trying to implement some cicd using GitLab runner,
I am very new to containers and trying to install the zip package in the container,
I was able to install awscli using pip but, I am not able to install the zip package, which is required for my shell script.
Following is the .gitlab-ci.yml file -
stages:
- build
build:
image: python:latest
stage: build
script:
- pip install awscli
- yum install zip
- bash cicdScript.sh
I'm using the python container, as my script requires awscli,
But also needs the zip package,
I tried the following -
1)
script:
- pip install awscli
- yum install zip
- bash cicdScript.sh
gives -
/bin/bash: line 82: yum: command not found
2)
script:
- pip install awscli
- apt-get install zip unzip
- bash cicdScript.sh
gives -
Reading package lists...
Building dependency tree...
Reading state information...
Package zip is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'zip' has no installation candidate
Try update and -y
apt-get update
apt-get install -y zip unzip
I'm able to install it with root user but I wanted to install it in a clean environment. My use case is to test the installation of another application with pip for the customer who is using python3.7.0
sudo apt-get update
sudo apt-get install build-essential libpq-dev libssl-dev openssl libffi-dev zlib1g-dev
sudo apt-get install python3-pip python3-dev
sudo apt-get install python3.7
Thanks.
(assuming python3.7 is installed)
Install virtualenv package:
pip3.7 install virtualenv
Create new environment:
python3.7 -m virtualenv MyEnv
Activate environment:
source MyEnv/bin/activate
To help anyone else who runs into the chicken & egg situation trying to use the above chosen answer, here's what solved it for me:
sudo apt install python3.7-venv
python3.7 -m venv env37
source env37/bin/activate
deactivate (when done using the environment)
I had installed python 3.7 using deadsnakes vs source:
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.7
In doing so I could run python3.7 --version but since I had no pip3.7 I could not install virtualenv as directed in the solution above. Luck would have it that deadsnakes has venv! Once I installed venv I could create my environment & be on my merry way
Handy official python page with venv info
So why didn't I use?:
python3.7 -m ensurepip
That was giving me:
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.7/dist-packages/easy_install.py'
Consider using the --user option or check the permissions.
Which left me with 3 choices:
use sudo (which is simple but I keep being told is frowned upon)
install with --user option which wasn't ideal in that I may not always be logged in as the same user
or install it in an environment which I'm told is the recommended route.
But see chicken egg above.. How do I install pip in environment when I can't create venv or virtualenv? Thus my workaround solution of installing venv from deadsnakes which allowed me to create the virtual environment to then install pip3.7:
(env37) user#ubuntu:~$ python3.7 -m ensurepip
(env37) user#ubuntu:~$ pip3.7 --version
pip 19.2.3 from /home/user/env37/lib/python3.7/site-packages/pip (python 3.7)
Some added information, if you are trying for some version like python 3.7.10, which might give following error upon executing pip3.7.10 install virtualenv
.pyenv/versions/3.7.10/bin/python: No module named virtualenv
So, in a general sense you can do the following steps:
[commands are specific to MacOs, I am currently using with the new M1 chip]
After installing 3.7.10 using pyenv, make it global.
brew update
brew install pyenv
set environment variables
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
look at the pyenv list to see if the version you install is there or not and install and make it global
pyenv install --list
pyenv install 3.7.10
pyenv global 3.7.10
create your virtual environment now with this version
python -m venv MyEnv
activate it
source MyEnv/bin/activate
Using pip on windows, you can do the following:
1.virtualenv --python "C:\\Python37\\python.exe" venv# use your own path
You will see something like this:
Running virtualenv with interpreter C:\Python37\python.exe
Using base prefix 'C:\Python37'
New python executable in C:\Users\XXXX\Documents\GitHub\MyProject\venv\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
2.C:\Users\XXXXX\Documents\GitHub\MyProject>cd venv
C:\Users\XXXXX\Documents\GitHub\MyProject\venv>cd Scripts
C:\Users\XXXXX\Documents\GitHub\MyProject\venv\Scripts>activate.
At the beginning of the command path, when you see (environment variable name) in this case (venv), this is a sign that your virtual environment is activated.
(venv) C:\Users\tuscar2001\Documents\GitHub\MyProject\venv\Scripts>
Please check the following link for more details:http://www.datasciencetopics.com/2020/03/how-to-set-up-virtual-environment-in.html
Figure out python3.7 path on your system. For mac with python3.7 in brew you can use the following
virtualenv env -p /usr/local/opt/python#3.7/bin/python3
source ./env/bin/activate