Search code examples
ansibleopenstack

Ansible: Run modules on a target host in a virtual enviroment


I want to run the os_server module on a target host which has a virtual enviroment where openstacksdk is installed. If I try to run the script as shown below it results in a error "conflicting action statements: virtualenv, os_server". How can I specify a virtual enviroment correctly so that ansible uses it? I don't want to install openstacksdk globally and just use the venv.

- name: Create Server
  virtualenv: "/home/user/otc2/bin/activate"
  os_server:
    state: present
    auto_ip: false
    ...

Solution

  • You would set the ansible_python_interpreter hostvar for that host to point to the python binary inside the virtualenv on the remote machine, which appears to be /home/user/otc2/bin/python based on your posted snippet