0
votes

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":
2
for which line it is showing error?vb_rises
on initialize condapankaj kumar

2 Answers

1
votes
  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
0
votes

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