使用Ansible安装Rbenv

时间:2014-02-05 22:16:30

标签: rbenv ansible ansible-playbook

我正在尝试使用Ansible在我的服务器上安装Rbenv,但收到此错误:

  

任务:[rbenv |创建临时目录] * ** * ** * ** * ** * ** * ****   致命的:[localhost] =>条件表达式必须计算为True或False:is_failed($ rbuild_present)

     

致命:所有主机都已经失败 - 正在中止

我的剧本是:

---
- name: rbenv | update rbenv repo
  git: repo=git://github.com/sstephenson/rbenv.git
       dest=$rbenv_root
       version=v0.4.0

- name: rbenv | add rbenv to path
  file: path=/usr/local/bin/rbenv
        src=${rbenv_root}/bin/rbenv
        state=link

- name: rbenv | add rbenv initialization to profile
  template: src=templates/rbenv.sh.j2
            dest=/etc/profile.d/rbenv.sh
            owner=root
            group=root
            mode=0755

- name: rbenv | check ruby-build installed
  command: test -x /usr/local/bin/ruby-build
  register: rbuild_present
  ignore_errors: yes

- name: rbenv | create temporary directory
  shell: mktemp -d
  register: tempdir
  when_failed: $rbuild_present

- name: rbenv | clone ruby-build repo
  git: repo=git://github.com/sstephenson/ruby-build.git
       dest=${tempdir.stdout}/ruby-build
  when_failed: $rbuild_present

- name: rbenv | install ruby-build
  command: ./install.sh
           chdir=${tempdir.stdout}/ruby-build
  when_failed: $rbuild_present

- name: rbenv | remove temporary directory
  file: path=${tempdir.stdout} state=absent
  when_failed: $rbuild_present

- name: rbenv | check ruby $ruby_version installed
  shell: RBENV_ROOT=${rbenv_root} rbenv versions | grep $ruby_version
  register: ruby_installed
  ignore_errors: yes

- name: rbenv | install ruby $ruby_version
  shell: RBENV_ROOT=${rbenv_root} rbenv install $ruby_version
  when_failed: $ruby_installed

- name: rbenv | set global ruby $ruby_version
  shell: RBENV_ROOT=${rbenv_root} rbenv global $ruby_version
  when_failed: $ruby_installed

- name: rbenv | rehash
  shell: RBENV_ROOT=${rbenv_root} rbenv rehash
  when_failed: $ruby_installed

- name: rbenv | set gemrc
  copy: src=files/gemrc
        dest=/root/.gemrc
        owner=root
        group=root
        mode=0644

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

我怀疑您使用的是最新的Ansible或> 1.3.x。不推荐使用when_语法,当您运行Playbook时,它会给您一个警告。而是使用类似的东西:

when: ruby_installed|failed

或类似的东西:

when: 'not ($ruby_installed)'