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.
Related
Currently, I am trying to use the ansible.builtin.expect.
Here is my usecase:
- name: Set password for built-in user
expect: command: '/usr/share/elasticsearch/bin/elasticsearch-keystore add "bootstrap.password" -f'
responses: Enter value for bootstrap.password: 'test'
To use ansible.builtin.expect I have to install:
python >= 2.6
pexpect >= 3.3
I have Python 2.7.5 installed, but if i want to install pexpect, it only installs version 2.3.
To install pexpect i use:
- name: Install pexpect module
yum:
name: pexpect
state: latest
Does anyone know, how I am able to install pexpect version 3.3?
Why not installing directly the pip version matching your requirement:
- name: Install pexpect throuhg pip
become: true
pip:
name: "pexpect>=3.3"
state: present
something like this maybe:
- name: 'install pexpect'
become: true
become_user: 'root'
yum:
name: '{{ item }}'
state: present
enablerepo: 'standard'
with_items:
- 'pexpect'
I am new to ansible and writing a playbook to install locustio with python3 on a Ubuntu 18.04. I don't know how to install locustio with pip3 in playbook. If use pip package, then it gives error to use older version of locust. ( use a pinned old locust version (pip/pip3 install locustio==0.13.5) . I would like to know how to install locust with pip3 or locust 0.13.5 version with pip?
- hosts: all
tasks:
- name: Create folder to keep the files
file:
path: /opt/locust
state: directory
mode: '0755'
become: yes
- name: Python installation
apt:
name: ['python3']
state: present
become: yes
- name: Pip installation
apt:
name: ['python3-pip']
state: present
become: yes
- name: pip install
apt:
name: ['python-pip']
state: present
become: yes
- name: Locust Installation
pip:
name: ['locustio']
state: present
become: yes
I haven't used Ansible, but looking at the docs there seems to be a executable parameter that you could set to pip3.
I need to create some snake-oil certificates on some playbook and I'm using openssl_privatekey, openssl_csr and openssl_certificate modules for this. The problem is that this module depens on PyOpenSSL and that CentOS versions of PyOpenSSL are outdated.
To workaround this I install PyOpenSSL from pip, which works, but may overwrite an already existing PyOpenSSL module if that was installed with yum.
On my playbook I'm doing this:
- name: 'Install PyOpenSSL'
pip:
name: PyOpenSSL
state: present
version: '>= 0.15'
Now, is there a way to install this in a virtual environment, so that ansible is aware of it? If so I can simply remove the virtual environment in the play's end.
You can create a virtualenv with the pip module. You can probably make Ansible aware of that virtualenv by setting the ansible_python_interpreter fact to point at the python binary in the virtualenv, so something like:
---
- hosts: localhost
gather_facts: false
tasks:
- name: install modules
pip:
state: present
name: "{{ modules }}"
virtualenv: /tmp/venv
vars:
modules:
- pyopenssl
- set_fact:
ansible_python_interpreter: /tmp/venv/bin/python
Caveat: I haven't tested this thoroughly. It didn't break anything.
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 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