ansible-conda icon indicating copy to clipboard operation
ansible-conda copied to clipboard

How to install packages into specific conda environment?

Open UncasRipley opened this issue 7 years ago • 2 comments

How do I use this module to install package to specific environment?

For example, Given that I have Anaconda installed under /opt/anaconda2/, and that I have manually created environment called 'myconda'

I want to write a task to install package pip into environment 'myconda'

Here is an example task:

  • name: Install pip via conda module conda: name: pip state: latest executable: /opt/anaconda2/bin/conda extra_args: - "-n myconda"

This does not work in my environment with ansible 2.4.3.0

UncasRipley avatar Apr 02 '18 20:04 UncasRipley

Do you get an error, or does it end up installing into the default environment?

jiffyclub avatar Apr 09 '18 16:04 jiffyclub

I feel the conda ansible module install should work like the conda create command and create the environment if it does not exist.

  • name: Create virtual environment rtp and install biopython conda: name=biopython state=latest extra_args="-n rtp" executable="{{ app_home }}/rtp/anaconda3/bin/conda"

Instead, conda ansible module errors: TASK [rtp-python : Create virtual environment rtp and install biopython] ************************* fatal: [eric-rtp-python.preprod.com]: FAILED! => {"changed": false, "module_stderr": "Shared connection to eric-rtp-python.preprod.com closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File "/tmp/ansible_XRIZTY/ansible_module_conda.py", line 373, in \r\n _main()\r\n File "/tmp/ansible_XRIZTY/ansible_module_conda.py", line 369, in _main\r\n conda, name, version, state, module.check_mode, command_runner, module.fail_json, module.exit_json)\r\n File "/tmp/ansible_XRIZTY/ansible_module_conda.py", line 94, in run_package_operation\r\n correct_version_installed = check_package_installed(command_runner, conda, name, version)\r\n File "/tmp/ansible_XRIZTY/ansible_module_conda.py", line 126, in check_package_installed\r\n command_runner, name, version, [conda, 'install', '--json', '--dry-run', get_install_target(name, version)])\r\n File "/tmp/ansible_XRIZTY/ansible_module_conda.py", line 239, in run_conda_package_command\r\n return command_runner(command)\r\n File "/tmp/ansible_XRIZTY/ansible_module_conda.py", line 366, in command_runner\r\n return run_conda_command(module, command)\r\n File "/tmp/ansible_XRIZTY/ansible_module_conda.py", line 333, in run_conda_command\r\n raise CondaCommandJsonDescribedError(command, output, stderr)\r\n__main.CondaCommandJsonDescribedError: Error running command: ['/home/app/rtp/anaconda3/bin/conda', 'install', '--name', 'rtp', '--json', '--dry-run', 'biopython']. stdout: {"exception_name": "EnvironmentLocationNotFound", "caused_by": "None", "exception_type": "<class 'conda.exceptions.EnvironmentLocationNotFound'>", "location": "/home/app/rtp/anaconda3/envs/rtp", "error": "EnvironmentLocationNotFound: Not a conda environment: /home/app/rtp/anaconda3/envs/rtp", "message": "Not a conda environment: /home/app/rtp/anaconda3/envs/rtp"}.\r\n", "msg": "MODULE FAILURE", "rc": 1}

ericpardee avatar Jun 11 '18 23:06 ericpardee