【发布时间】:2017-06-12 13:31:17
【问题描述】:
我正在尝试使用 Ansible 为 Elixir 编程语言安装 Kiex 版本管理器。
这些是我为此使用的剧本:
- name: Kiex Installation
hosts: web
gather_facts: false
remote_user: deployer
tasks:
- shell: \curl -sSL https://raw.githubusercontent.com/taylor/kiex/master/install | bash -s
- name: Add Kiex Bin to Path
lineinfile:
dest: /home/deployer/.bashrc
regexp: '^test -s'
line: '[[ -s "$HOME/.kiex/scripts/kiex" ]] && source "$HOME/.kiex/scripts/kiex"'
- name: Reload Path
shell: source /home/deployer/.bashrc
args:
executable: /bin/bash
- shell: echo $PATH
register: pathul
- debug:
var: pathul
- name: Elixir Installation
hosts: web
gather_facts: false
remote_user: deployer
tasks:
- shell: echo $PATH
register: pathul
- debug:
var: pathul
- name: Install Elixir Version
command: /home/deployer/.kiex/bin/kiex list
args:
executable: /bin/bash
chdir: /home/deployer/
- name: Set Elixir Version as Default
shell: kiex default 1.4
Kiex 的安装是成功的,如果我登录到远程机器,我只需使用kiex 命令就可以运行它。我可以这样做是因为我在“~/.kiex/scripts/kiex”中获取了二进制文件。当我回显 $PATH 变量时,它会在其中显示 kiex 二进制文件路径 /home/deployer/.kiex/bin:
$ echo $PATH
/home/deployer/.kiex/bin:/home/deployer/.kiex/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
但是,上面显示的 Elixir 安装中的 kiex、kiex list 甚至 /home/deoployer/.kiex/bin/kiex list 播放失败并显示以下消息:
TASK [Set Elixir Version as Default] *******************************************
fatal: [local-web-2]: FAILED! => {"changed": true, "cmd": "kiex default 1.4", "delta": "0:00:00.002042", "end": "2017-01-26 22:13:32.898082", "failed": true, "rc": 127, "start": "2017-01-26 22:13:32.896040", "stderr": "/bin/sh: 1: kiex: not found", "stdout": "", "stdout_lines": [], "warnings": []}
另外pathul变量注册了通过ansible回显路径的结果不包含/home/deployer/.kiex/bin:
"stdout": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
如何通过 Ansible 使 kiex 命令正常工作?
【问题讨论】:
标签: bash path ansible elixir ansible-playbook