0

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..

Hari
  • 89
  • 1
  • 2
  • 9

1 Answers1

1

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
Alassane Ndiaye
  • 4,427
  • 1
  • 10
  • 19