我正在教自己ansible,我有两个简单的文件。我想在数字海洋服务器上安装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
^
但是,如果我进入机器,确切的命令似乎工作正常。
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
任何人都可以指出我的剧本有什么问题吗?
答案 0 :(得分:1)
您正在做的事情看起来很好,但command
一般来说更安全一点,您可以使用Rscript
来执行任务并避免回显和管道
- command: Rscript --vanilla -e "install.packages('plyr', repos=c('http://www.freestatistics.org/cran/'))"
如果您安装了littler(这是一个apt-get
个软件包),您可以发出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