我正在用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”:
答案 0 :(得分:1)
似乎您正在执行错误的命令。应该是“ conda init”而不是“ init conda”
您可以将两个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