Install Rbenv using Ansible

情到浓时终转凉″ 提交于 2020-01-15 21:03:20

问题


I am trying to install Rbenv on my server using Ansible but getting this error:

TASK: [rbenv | create temporary directory] ******************** fatal: [localhost] => Conditional expression must evaluate to True or False: is_failed($rbuild_present)

FATAL: all hosts have already failed -- aborting

My playbook is:

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

Any ideas?


回答1:


I suspect you are using the latest Ansible or > 1.3.x . The when_ syntax has been deprecated, when you run your playbook it should give you a warning. Instead use something like:

when: ruby_installed|failed

or something like:

when: 'not ($ruby_installed)'


来源:https://stackoverflow.com/questions/21589745/install-rbenv-using-ansible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!