Menu

Ansible cannot find your new role: where roles must live and how to create one
📰

Ansible cannot find your new role: where roles must live and how to create one

DEV Community: ansible·Vitalii Shumylo·5 days ago
#ggzVt5i3
#devtoansible#devto#dev#roles#role
Reading 0:00
15s threshold

You write a role, add it to a playbook and run it. Ansible stops before the first task. It says the role was not found and prints a list of folders. The role is on the disk, so why can Ansible not see it?

Ansible does not search the whole disk for roles. It checks a short list of places: collections, if you use them, then a roles/ folder next to the playbook, then the folders in roles_path , and then the folder of the playbook itself. A role that you created in your home folder, or inside another project, is not in any of these places.

The simple fix is to create the role in the right place from the start. ansible-galaxy builds the standard folder layout for you, and --init-path tells it where to put that layout:

mkdir -p roles ansible-galaxy role init --init-path roles chrony ansible-playbook -i inventory site.yml

Enter fullscreen mode

Exit fullscreen mode

Here site.yml is in the same folder as roles/ , and it lists chrony under roles: .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.