Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: Can I execute role from command line?

Suppose I have a role called "apache"

Now I want to execute that role on host 192.168.0.10 from the command line from Ansible host

ansible-playbook -i  "192.168.0.10" --role  "path to role" 

Is there a way to do that?

like image 272
Karl Avatar asked Jul 13 '16 11:07

Karl


People also ask

How do you execute an Ansible role?

There is no way to directly execute a role. Roles have no explicit setting for which host the role will apply to. Top-level playbooks are the bridge holding the hosts from your inventory file to roles that should be applied to those hosts.


1 Answers

With ansible 2.7 you can do this:

$ cd /path/to/ansible/ $ ansible localhost -m include_role -a name=<role_name> localhost | SUCCESS => {     "changed": false,     "include_variables": {         "name": "<role_name>"     } } localhost | SUCCESS => {     "msg": "<role_name>" } 

This will run role from /path/to/ansible/roles or configured role path.

Read more here: https://github.com/ansible/ansible/pull/43131

like image 144
Julius Žaromskis Avatar answered Sep 22 '22 02:09

Julius Žaromskis