-1

Hi I am trying to get miniconda base path, to set the PATH but fail to get it, tried with shell and command , output getting as same input : "conda info | grep -i 'conda av data dir'|awk '{print $6}'"

-name: get_conda_path
shell: echo $(conda info | grep -i 'conda av data dir'|awk '{print $6}')
register: conda_path
- set_fact:
path: "{{conda_path.stdout}}"

Attached output image for the refrenceenter image description here

santhosh
  • 1
  • 6

1 Answers1

0

That's simply because of echo used as part of shell module.

When you remove echo, ansible executes conda info command & then applies the grep followed by awk..

- name: get_conda_path
  shell: "conda info | grep -i 'conda av data dir'|awk '{print $6}'"
  register: conda_path

- set_fact:
  path: "{{conda_path.stdout}}"
harshavmb
  • 3,404
  • 3
  • 21
  • 55
  • for this command not working shell: "conda create -n wme_sst_env python=3.9.7 -y" – santhosh Apr 10 '22 at 16:29
  • It's not related to above question, post another question – harshavmb Apr 10 '22 at 16:30
  • add new question https://stackoverflow.com/questions/71818978/need-to-create-environment-for-python-by-conda-in-ansible – santhosh Apr 10 '22 at 17:25
  • 1
    Using grep piped with awk is redundant in most cases, like this one. You can use awk like `awk '/something to search/{print $6}'` – P.... Apr 10 '22 at 20:12
  • TBH, I’m not a fan of `shell` & that too for fetching/parsing something from output. It’s better to use `pattern` with `regex_search`. The command was working without `echo` & I just posted that as an answer.. – harshavmb Apr 10 '22 at 20:30
  • it is nnot working – santhosh Apr 11 '22 at 07:07
  • @santhosh, what's not working? Can you be more specific? An error log would be of some use rather saying `not working` – harshavmb Apr 11 '22 at 07:29
  • - name: get_conda_path shell: "conda info | grep -i 'conda av data dir'|awk '{print $6}'" register: conda_path - set_fact: path: "{{conda_path.stdout}}" and error getting as commad not found – santhosh Apr 11 '22 at 07:32
  • that means you haven't got any `conda` installed. If installed, it's not on the PATH which OS expects. – harshavmb Apr 11 '22 at 07:36
  • My task is install miniconda and set path, Installation is success , to set env path only i using above command to get conda path – santhosh Apr 11 '22 at 07:38
  • works => command : /bin/bash -l -c "conda info | grep -i 'conda av data dir'|awk '{print $6}'" – santhosh Apr 11 '22 at 07:48