2016-02-13 211 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