康达没有使用ansible剧本进行初始化

时间:2019-05-25 11:00:22

标签: python ansible anaconda

我正在用ansible自动化conda安装,但是激活conda的最后一步(conda init)失败了。

我尝试运行conda init,因为shell脚本和命令模块全部失败。

代码:

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

错误:

  
      
  • “ stderr”:“预期的单字符参数。”,“ stderr_lines”:
  •   

2 个答案:

答案 0 :(得分:1)

  1. 似乎您正在执行错误的命令。应该是“ conda init”而不是“ init conda”

  2. 您可以将两个Shell任务组合在一起并可以执行它。 更新后的代码如下:

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

答案 1 :(得分:0)

shell 模块设置的变量 PATH 仅在此任务(shell会话)中可用。试试

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