0

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) and its job is to install two R packages from CRAN. This is my (successful) playbook task:

- 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 (successfully installs those two packages). 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:

- 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 do what I expect: I have created lots of roles, with lots of tasks, and this is the only task I can't get to achieve the same result inside as a role as it does in my playbook. 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,

Mike

Mike
  • 1
  • 1
  • 3
  • You should consider banning "It's not working" from your vocabulary on Q&A sites like SO, at least when used on its own. [It does not accurately describe your problem](http://idownvotedbecau.se/itsnotworking/) – Zeitounator Jun 02 '21 at 09:43

1 Answers1

0

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 }}"
Mike
  • 1
  • 1
  • 3