yaobin.wen

Yaobin's Blog

View on GitHub
23 December 2022

Ansible: How to display a role's path

by yaobin.wen

When we debug a playbook, sometimes we want to figure out the actual path of the role in the playbook. As of v2.9.12, there doesn’t seem to be a CLI option of ansible or ansible-playbook to show the role paths. But there are two other methods to do it.

The first method uses the debug output: Run export ANSIBLE_DEBUG=1 to enable debugging output. Then look for the debug log messages “Loading data from”:

 15267 1639582174.41790: Loading data from /home/ywen/ansible/roles/demo/defaults/main.yml
 15267 1639582174.41857: Loading data from /home/ywen/ansible/roles/demo/tasks/main.yml

The second method is to hack the code (assuming v2.9.27):

        # first we pull the role name out of the data structure,
        # and then use that to determine the role path (which may
        # result in a new role name, if it was a file path)
        role_name = self._load_role_name(ds)
        (role_name, role_path) = self._load_role_path(role_name)
        (role_name, role_path) = self._load_role_path(role_name)
        display.v("Found role '{n}' at '{p}'".format(n=role_name, p=role_path))
TASK [Task description] *********************************************************************************************************
Found role 'demo' at '/home/ywen/ansible/roles/demo'
Tags: Tech - Ansible