通过shell安装r包时出现ansible错误

问题描述 投票:0回答:1

我正在教自己ansible,我有两个简单的文件。我想在数字海洋服务器上安装R和一些软件包。

hosts
[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
^

但是,如果我进入机器,确切的命令似乎工作正常。

root@<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

任何人都可以指出我的剧本有什么问题吗?

r shell ansible ansible-playbook
1个回答
1
投票

你正在做什么看起来很好,但command一般更安全,你可以使用Rscript来执行任务,避免回声和管道:

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

如果您安装littler(这是一个apt-get-able包),您可以发出command将其链接到一般可用的位置:

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

然后使用它非常简洁地进行进一步的pkg安装:

- command: install.r plyr
© www.soinside.com 2019 - 2024. All rights reserved.