2016-02-13 223 views
0

我正尝试使用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操作手册(使用shell模块)运行这些命令时,系统找不到指南针命令。

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

我已经尝试使用apt安装rubydev和rubygems集成,然后使用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 
    ... 

会爱一些帮助。

+0

你可以发布你的剧本吗? – ydaetskcoR

+0

它失败了什么任务? – ydaetskcoR

+0

就像我上面写的 - 当前剧本运行成功,但是当我尝试运行指南针编译甚至指南针-v失败时(手动安装时它工作正常) –

回答

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\"" 
... 
1

您也可以使用宝石模块它比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 

顺便说一句,你可以看到更多关于宝石模块这里到ansible文档:http://docs.ansible.com/ansible/latest/gem_module.html