这是我的剧本中负责从源代码下载和构建 ruby 的部分:
vars:
ruby_version: '2.0.0-p247'
ruby_url: 'ftp://ftp.ruby-lang.org//pub/ruby/2.0/ruby-{{ ruby_version }}.tar.gz'
tasks:
- name: Ensure ruby dependencies are installed
apt: pkg=$item state=installed update-cache=yes
sudo: yes
with_items:
- build-essential
- git-core
- libreadline6-dev
- libyaml-dev
- libsqlite3-dev
- sqlite3
- libgdbm-dev
- libncurses5-dev
- libtool
- bison
- libffi-dev
- libdigest-hmac-perl
- unzip
- zlib1g
- zlib1g-dev
- name: Ensure the ruby source is downloaded
get_url: url=$ruby_url dest=/home/vagrant/ruby-{{ ruby_version }}.tar
- name: Ensure the ruby source is extracted
command: tar -zxf /home/vagrant/ruby-$ruby_version.tar creates=/home/vagrant/ruby-{{ ruby_version }}
- name: Ensure ruby is installed
command: $item chdir=/home/vagrant/ruby-$ruby_version
with_items:
- ./configure
- make
- sudo make install
最后一个任务(配置 make 和 make install)在每次配置时运行。
我可以检查 ruby 是否已经安装了正确的版本ruby -v
。如何在我的剧本中定义这是运行此步骤的条件?
另外,有没有办法让这成为整个任务列表的条件,而不仅仅是最后一个?