Reputation: 1158
I have a use case to use R's devtools::install_github
---
- hosts: slurm_w
vars:
arg: "USCbiostats/slurmR"
tasks:
- debug: var=arg
- shell: R -e devtools::install_github({{ arg }})
register: find
- debug: var=find.stdout.lines
What I'd like to do is write plays that can use install_github
I know there is another method: githubinstall("PackageName") which is easier to work with, but ultimately I'd like a solution to work around the forward slash
The only way I can really get this to install as is is to use a bash script that I ultimately call from an ansible play
error
fatal: [slurmw01]: FAILED! => {"changed": true, "cmd": "R -e devtools::install_github(\\\"USCbiostats/slurmR\\\")", "delta": "0:00:00.004260", "end": "2020-12-21 21:19:26.638852", "msg": "non-zero return code", "rc": 1, "start": "2020-12-21 21:19:26.634592", "stderr": "/bin/sh: -c: line 0: syntax error near unexpected token `('\n/bin/sh: -c: line 0: `R -e devtools::install_github(\\\"USCbiostats/slurmR\\\")'", "stderr_lines": ["/bin/sh: -c: line 0: syntax error near unexpected token `('", "/bin/sh: -c: line 0: `R -e devtools::install_github(\\\"USCbiostats/slurmR\\\")'"], "stdout": "", "stdout_lines": []}
Upvotes: 0
Views: 672
Reputation: 7340
This issue is occurring because of extra quotes required for the expression (-e
) passed to the R command.
Typically run like:
R -e "devtools::install_github('USCbiostats/slurmR')"
We can escape the quotes, like so:
- shell: "R -e \"devtools::install_github('{{ arg }}')\""
register: find
Upvotes: 1
Reputation: 33223
As the message clearly says, it's not the forward slashes, it's the open paren which is a shell metacharacter
You need to escape the expression that is provided to -e
to keep bash from trying to interpret the (
. The easiest way is via the | quote
filter
- shell: R -e {{ ('devtools::install_github("' ~ arg ~ '")') | quote }}
register: find
Upvotes: 1