Allow roles to be applied from the command line

Hi there,

I just started using Ansible, and coming from other provisioning tools, I created several different roles.
On the documentation you are able to run ansible webservers -m service -a "name=httpd state=running" and apply a module to several different servers.

The flow I was imagining was that I would be able to choose a set of servers, and with the ansible command, apply roles, the same way we apply a module.
I looked up on the arguments that you could pass to the command, and it does not accept roles.

Asking on IRC, the suggested way was to generate a minimal playbook on the fly, similar to

---
- hosts: all
role:
- webserver

I think it is not the ideal way. It is more of a workaround and reflects that roles are not first-class concepts on Ansible.
I thought that we could add --role option to ansible command, or even create a role module that apply roles.

As I just start with Ansible, I am not familiar with the code base as well as the ways you can extend Ansible (eg: modules).

How do you see this working? Where do you suggest to start digging into?
I would love to help on this and hear suggestion on where to start.

Cheers,

Hi there,

I took a look on the code to see how it could be done and I felt a bit overwhelmed by it.

I then wrote a bash script that generates a temporary playbook with just the role, executes ansible-playbook and removes it.
I will leave the link for future reference https://github.com/bltavares/dot-files/commit/54958fc1d6c039c26aa82d8efdd10d701bd7e3a3

Cheers,

Yep, runner is not where the role and playbook logic is maintained, so this would be the way to go if you wanted this.