I want to pip install with --upgrade, using Ansible.
What's the syntax?
- name: install the package, force upgrade
pip:
name: <your package name>
state: latest
Or with:
- name: install the package, force reinstall to the latest version
pip:
name: <your package name>
state: forcereinstall
Eventually found the answer here:
https://groups.google.com/forum/#!topic/ansible-project/a19JEpdXzck
this is the syntax:
- name: install the package, force upgrade
pip:
name: <your package name>
extra_args: --upgrade
If you need upgrade pip for other python version, you can use executable parameter:
- name: install the package, force upgrade
pip:
name: pip
executable: pip3
state: latest
Related
Ansible version: 2.9
Python version being used: 3.6+
OS: ubuntu 18
Trying to remove docker-py using pip.
Code snippets I have tried...
post_tasks:
- pip:
name: docker-py
state: absent
- name: remove docker-py sdk
pip:
name: docker-py
state: absent
Document referred: https://docs.ansible.com/ansible/2.9/modules/docker_container_module.html
package never gets uninstalled.
Direct pip command from shell works
pip uninstall docker-py
- name: remove docker-py sdk
become: no
pip:
name: docker-py
state: absent
I had become: yes for the whole ansible-playbook, i did a override for this task, so may be we should avoid become: yes for pip packages.
Could anyone please support with equivalent tasks for clean and remove ?
yum clean expire-cache
yum -y remove packageX-S
yum -y install packageX-S
I got install already...
- name: deploy
yum:
name: llc-html-clients-S
state: latest
TL;DR;
Here are your equivalent tasks:
- name: clean
command: yum clean expire-cache
- name: remove
yum:
name: pkg-to-remove
state: absent
- name: install
yum:
name: pkg-to-install
state: present
Installing and removing is done with the same module yum.
When installing would test the installed or present state, removing is about testing removed or absent state.
Install:
- name: install
yum:
name: pkg-to-install
state: present
Take care: yum install and state: latest are not the same, when the yum command will install if the package is absent and do nothing if it is present already, state: latest will do an install if the package is absent but also a yum update pkg-to-install if the package is not at its latest version.
The real equivalent is state: present.
present and installed will simply ensure that a desired package is installed.
latest will update the specified package if it's not of the latest available version.
Source: https://docs.ansible.com/ansible/latest/modules/yum_module.html#parameter-state
Remove:
- name: remove
yum:
name: pkg-to-remove
state: absent
Then for the clean, sadly, there was a choice to not implement it, as this is not something that can be done in an idempotent way.
See this note on yum module page
The yum module does not support clearing yum cache in an idempotent way, so it was decided not to implement it, the only method is to use command and call the yum command directly, namely “command: yum clean all”
https://github.com/ansible/ansible/pull/31450#issuecomment-352889579
Source: https://docs.ansible.com/ansible/latest/modules/yum_module.html#notes
So as pointed in the note, you could actually go by a simple command.
- name: clean
command: yum clean expire-cache
So those are equivalent:
in bash
yum clean expire-cache
yum -y remove pkg-to-remove
yum -y install pkg-to-install
in playbook
- name: clean
command: yum clean expire-cache
- name: remove
yum:
name: pkg-to-remove
state: absent
- name: install
yum:
name: pkg-to-install
state: present
I was using ansible to install pexpect on both my vagrant box and also onto my host. When I installed pexpect onto both computers, the version is 4.6.0, but when using ansible to install using apt-get, the maximum version is only 3.1. The error message thrown is: "Insufficient version of pexpect installed (3.1), this module requires pexpect>=3.3. Error was __init__() got an unexpected keyword argument 'echo'"}How am I able to install pexpect in order to use the expect module for ansible?
The code for downloading pexpect is
- hosts: all
become: yes
become_user: root
gather_facts: no
#can use sudo/sudo_user instead of become, but thats depreceated in ansible 2.6 or later
tasks:
- name: download pip
apt: name=python3-pip state=latest
- name: update pexpect
command: pip3 install pexpect
command: pip3 install --upgrade pip3
command: pip3 install --upgrade pexpect
Run a task per command and try to use Ansible pip module.
- name: Install Pexpect
hosts: all
become: True
become_user: root
gather_facts: False
tasks:
- name: download pip
apt:
name: python3-pip
state: latest
- name: Install Pexpect
pip:
name: pexpect
state: latest
- name: Upgrade pip - Force reinstall to the latest version
pip:
name: pip
state: forcereinstall
I'd like to convert the following to a Ansible pip task:
- name: install packages and setup profile 3
shell: pip install --user vex
I do not see anything in the Ansible documentation for installing for user.
You can use the pip module with extra_args parameter:
- name: install packages and setup profile 3
pip:
name: vex
state: present
extra_args: --user
Ansible passes the value given in the parameter directly to the pip command.
I've installed ansible via the ubuntu apt package ansible, I am trying to use the npm module which is an extras module, which is provided only in the ansible-modules-extras Github repository.
How do I install ansible-modules-extras?
Looking at where files were installed as part of the ansible apt package, I would guess I have to merge some of the source codes folders to like /usr/share/ansible
or somewhere under /usr/lib/python2.7/dist-packages/ansible.
I ask this as I get this error from the Ansible output:
msg: Failed to find required executable npm
Ansible extras are included in the Ubuntu ansible apt package.
The target machine must have npm installed, apt package npm, can be installed like so via Ansible:
tasks:
- name: install npm
apt: pkg=npm state=present
Try to install with python-pip, for this first time delete the ansible.
sudo apt-get remove ansible
After install python-pip
sudo apt-get install gcc python-pip python-dev
And install ansible
sudo pip install ansible
It is install the newest version. It should contain the npm mondule.