pankaj kumar
pankaj kumar

Reputation: 11

conda not getting initialize using ansible playbook

I am automating conda installation with ansible but the last step of getting the conda activated (the conda init ) getting failed.

I tried to run conda init as shell script and command module all failed.

Code:

---
  - hosts: all
    gather_facts: true
    tasks:
     - name: Ansible copy file to remote server
       copy:
         src: ~/Downloads/Anaconda3-2019.03-Linux-x86_64.sh
         dest: ~/Downloads/Anaconda3-2019.03-Linux-x86_64.sh
     - name: Run the installer Anaconda
       command: bash ~/Downloads/Anaconda3-2019.03-Linux-x86_64.sh -b 
     - name: add path
       shell: export PATH=~/anaconda3/bin:$PATH
     - name: initialize conda
       shell: init conda
       args:
        executable: /bin/bash

Error:

  • "stderr": "Expected single character argument.", "stderr_lines":

Upvotes: 0

Views: 2262

Answers (2)

Ravi Kulkarni
Ravi Kulkarni

Reputation: 667

  1. It seems you are executing wrong command. It should be "conda init" instead of "init conda"

  2. you can combine both shell task in one and can execute it. Updated code is as follows:

---
  - hosts: all
    gather_facts: true
    tasks:
     - name: Ansible copy file to remote server
       copy:
         src: ~/Downloads/Anaconda3-2019.03-Linux-x86_64.sh
         dest: ~/Downloads/Anaconda3-2019.03-Linux-x86_64.sh
     - name: Run the installer Anaconda
       command: bash ~/Downloads/Anaconda3-2019.03-Linux-x86_64.sh -b 

     - name: Add path and initialize conda
       shell: export PATH=~/anaconda3/bin:$PATH && conda init
       args:
        executable: /bin/bash

Upvotes: 2

Vladimir Botka
Vladimir Botka

Reputation: 68189

The variable PATH, set by the shell module is available in this task (shell session) only. Try

shell: "export PATH=~/anaconda3/bin:$PATH; init conda"
args:
  executable: /bin/bash

Upvotes: 0

Related Questions