2014-10-11 161 views
0

我在教自己,我有兩個簡單的文件。我想在數字海洋服務器上安裝R和一些軟件包。通過shell安裝r軟件包時出現錯誤

主機
[droplets] 
<IP ADRESS> 
playbook.yml
- hosts: droplets 
    user: root 
    sudo: true 
    vars: 
    - foo: Hello There Ansible 
    tasks: 
    - name: install R 
     apt: name=r-base state=installed 
    - name: install plyr 
     shell: echo "install.packages('plyr', repos=c('http://www.freestatistics.org/cran/'))" | R --no-save 

我從this question明白我不應該使用command選項,但shell命令。

我仍然得到這個錯誤。

$ ansible-playbook -i hosts -k playbook.yml 
SSH password: 
ERROR: Syntax Error while loading YAML script, playbook.yml 
Note: The error may actually appear before this position: line 10, column 1 

    - name: install plyr 
     shell: echo "install.packages('plyr', repos=c('http://www.freestatistics.org/cran/'))" | R --no-save 
^ 

但是,如果我ssh進入機器,確切的命令似乎工作正常。

[email protected]<IP ADRESS>:~# echo "install.packages('plyr', repos=c('http://www.freestatistics.org/cran/'))" | R --no-save 

R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows" 
Copyright (C) 2012 The R Foundation for Statistical Computing 
ISBN 3-900051-07-0 
Platform: x86_64-pc-linux-gnu (64-bit) 

R is free software and comes with ABSOLUTELY NO WARRANTY. 
You are welcome to redistribute it under certain conditions. 
Type 'license()' or 'licence()' for distribution details. 

    Natural language support but running in an English locale 

R is a collaborative project with many contributors. 
Type 'contributors()' for more information and 
'citation()' on how to cite R or R packages in publications. 

Type 'demo()' for some demos, 'help()' for on-line help, or 
'help.start()' for an HTML browser interface to help. 
Type 'q()' to quit R. 

> install.packages('plyr', repos=c('http://www.freestatistics.org/cran/')) 
Installing package(s) into ‘/usr/local/lib/R/site-library’ 
(as ‘lib’ is unspecified) 
Warning: dependency ‘Rcpp’ is not available 
trying URL 'http://www.freestatistics.org/cran/src/contrib/plyr_1.8.1.tar.gz' 
Content type 'application/x-gzip' length 393233 bytes (384 Kb) 
opened URL 
================================================== 
downloaded 384 Kb 

任何人都可以指出我的劇本有什麼問題嗎?

+0

你跑哪個版本?你的playbook在這裏運行得很好。 – leucos 2014-10-11 10:27:43

回答

1

你在做什麼看起來不錯,但command是一般比較安全,你可以使用Rscript來執行任務,避免呼應&管道:

- command: Rscript --vanilla -e "install.packages('plyr', repos=c('http://www.freestatistics.org/cran/'))" 

如果安裝littler(這是一個apt-get -able包),那麼你可以發出command將其鏈接到一個一般可用位置:

- apt: name=littler state=installed 
- command: ln -s /usr/share/doc/littler/examples/install.r /usr/local/bin/install.r 

然後用它做進一步的PKG插件高大很簡潔:

- command: install.r plyr 
+1

不僅「命令」更「安全」,而且** shell顯式不能用於管道**。 – tedder42 2014-10-11 19:48:08

+0

Rscript命令似乎運行沒有錯誤,但是當我ssh到機器我不能確認'''plyr'''已安裝。這是來自任務'''TASK的輸出:[command Rscript --vanilla -e「install.packages('plyr',repos = c('http://www.freestatistics.org/cran/'))」 ] *** 已更改:[37.139.10.170] 播放回放********************************** ********************************** 37.139.10.170:ok = 3 changed = 1 unreachable = 0 failed = 0''' – cantdutchthis 2014-10-12 09:03:13

+0

我也嘗試過你的littler安裝程序,並在輸出中得到相同的結果。 '''TASK:[command install.r dplyr,ggplot2,stringr] ******************************* 已更改: [37.139.10.170]'''任何想法該怎麼辦?它似乎並沒有實際安裝任何東西...... – cantdutchthis 2014-10-21 22:06:13