# How to move an ansible task (to install R packages) from a playbook to a role?

**URL:** <https://forum.ansible.com/t/how-to-move-an-ansible-task-to-install-r-packages-from-a-playbook-to-a-role/35270>\
**Category:** Ansible Project\
**Created:** [June 1, 2021, 10:51pm UTC](https://forum.ansible.com/t/how-to-move-an-ansible-task-to-install-r-packages-from-a-playbook-to-a-role/35270 "2021-06-01T22:51:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maspotts](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@maspotts](https://forum.ansible.com/u/maspotts)\
**Post date:** [June 1, 2021, 10:51pm UTC](https://forum.ansible.com/t/how-to-move-an-ansible-task-to-install-r-packages-from-a-playbook-to-a-role/35270/1 "2021-06-01T22:51:48Z")

</div>

I’m automating my mac setup using ansible, having great success. I just can’t figure out how to move one particular task from my playbook (where it succeeds) to a role. The task relies on a module (or possibly a role: it’s not entirely clear to me from the context): yutannihilation.module-cran (see: [https://github.com/yutannihilation/ansible-module-cran](https://github.com/yutannihilation/ansible-module-cran)) and its job is to install two R packages from CRAN. This is my (successful) playbook task:

```auto

- hosts: mac

roles:

- yutannihilation.module-cran

environment:

PATH: /opt/brew/bin:{{ ansible_env.PATH }}

tasks:

- name: Install R packages

cran: name={{ item }} state=present

with_items:

- tuneR

- seewav

```

where it works fine. I’ve now created a role av\_dev, and in roles/av\_dev/tasks/main.yml I have tried all manner of things: this is the only form in which ansible doesn’t error out, but unfortunately it also doesn’t install the packages:

```auto

- name: Install AV dev R packages

include_role:

name: yutannihilation.module-cran

vars:

name: "{{ item }}"

state: present

environment:

PATH: /opt/brew/bin:{{ ansible_env.PATH }}

with_items:

- tuneR

- seewave

```

Note: it’s only this task that doesn’t work: I have created lots of roles, with lots of tasks, and this is the only task I can’t get to work inside a role. I assume (hope) that it is possible to call this module/role from within my role; if anyone can show me how to do it I’ll be very grateful: and no doubt understand ansible a little better as a result. Many thanks,

Note: this is cross-posted to stack overflow ([https://stackoverflow.com/questions/67794835/how-to-move-this-ansible-task-to-install-r-packages-from-a-playbook-to-a-role](https://stackoverflow.com/questions/67794835/how-to-move-this-ansible-task-to-install-r-packages-from-a-playbook-to-a-role)) but I realized this forum is much more appropriate!

Mike

---

<div class="post-metadata">

**Author:** ![maspotts](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@maspotts](https://forum.ansible.com/u/maspotts)\
**Post date:** [June 3, 2021, 3:43pm UTC](https://forum.ansible.com/t/how-to-move-an-ansible-task-to-install-r-packages-from-a-playbook-to-a-role/35270/2 "2021-06-03T15:43:35Z")

</div>

Nevermind: I figured it out: I had confused the role with the module. Turns out I don’t need to reference the role at all:

- name: Install AV dev R packages  
cran: name={{ item }} state=present  
with\_items:
- tuneR
- seewave  
environment:  
PATH: “{{ homebrew\_prefix }}/bin:{{ ansible\_env.PATH }}”
