Ansible: Can I execute role from command line?

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


I am not aware of this feature, but you can use tags to just run one role from your playbook.

roles:
    - {role: 'mysql', tags: 'mysql'}
    - {role: 'apache', tags: 'apache'}

ansible-playbook webserver.yml --tags "apache"