用ansible安装指南针

时间:2016-02-13 17:45:04

标签: rubygems ansible ansible-playbook compass

我正在尝试使用Ansible在EC2服务器上安装我们的某项服务所需的指南针。 通常我们使用以下命令手动安装它 -

curl -L https://get.rvm.io | bash -s stable
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.1.2
rvm use 2.1.2 --default
gem install compass

然后成功运行指南针编译。 现在,当我尝试使用Ansible playbook(使用shell模块)运行这些命令时,系统找不到compass命令。

我尝试过使用RVM官方Ansible角色(https://github.com/rvm/rvm1-ansible),而我得到的只是更多错误。

我尝试使用apt安装rubydev和rubygems-integration,然后使用gem模块安装gem。这确实识别了罗盘命令但是当我尝试编译甚至显示指南针版本时它会返回错误。以下是运行指南针-v的错误,例如:

Errno::ENOENT on line ["25"] of /usr/lib/ruby/vendor_ruby/compass/version.rb: No such file or directory - /usr/lib/ruby/vendor_ruby/compass/../../VERSION.yml
Run with --trace to see the full backtrace  

这是设法安装罗盘的剧本,但让我知道我提到的错误:

---
- hosts: "{{ host_name }}"
  become: yes
  become_method : sudo
  tasks:
    - name: install ruby-dev
      apt: 
        name: ruby-dev
    - name: install rubygems
      apt: 
        name: rubygems-integration
    - name: install ruby compass
      apt: 
        name: ruby-compass
  ...

会喜欢一些帮助。

2 个答案:

答案 0 :(得分:1)

您也可以使用gem模块,它比shell脚本更好,因为它不依赖于您使用的Linux发行版,例如:

一个剧本示例

- name: Installing ruby
  apt:
    pkg: "{{ item }}"
    state: present
  with_items:
    - ruby2.0
    - ruby2.0-dev

- name: Symlink exists for Ruby 2.0
  file: src=/usr/bin/ruby2.0 dest=/usr/local/bin/ruby state=link

- name: Symlink exists for Ruby Gems 2.0
  file: src=/usr/bin/gem2.0 dest=/usr/local/bin/gem state=link

- name: install compass
  gem:
    name: compass
    state: latest

顺便说一句,您可以在此处查看有关gem模块的更多内容:http://docs.ansible.com/ansible/latest/gem_module.html

答案 1 :(得分:0)

这是最终为我安装罗盘的剧本 -

---
- hosts: "{{ host_name }}"
  become: yes
  become_user : deploy3
  tasks:
    #- name: get gpg
    #  shell: "gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3"
    - name: install rvm
      shell: "curl -L https://get.rvm.io | bash -s stable"
    - name: install rvm 2.1.2
      shell: "/home/deploy2/.rvm/bin/rvm install 2.1.2"
    - name: use rvm 2.1.2 by default and install compass
      shell: "bash -lc \"/home/deploy2/.rvm/bin/rvm use 2.1.2 --default && /home/deploy3/.rvm/rubies/ruby-2.1.2/bin/gem install compass\""
...
相关问题