Install Rbenv using Ansible

2019-07-23 20:22发布

问题:

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