简体   繁体   中英

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":
  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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM