Passing variables to ansible roles


I have my directory structure as this

When I am creating a user under the role create_new_user, I was hard coding the user name as

One way of solving this may be to create a var/main.yml and put the username there. But I wanted something through which I can specify the username at play.yml level. As I am also using the username in the role vimrcserver.

I am calling the roles using play.yml

Would a template work here in this case? Couldn’t find much from these!


I got it working by doing a

on play.yml

Although would love to see a different approach then this


I finally settled with a directory structure like

Where I am creating a defaults/main.yml file inside the roles where I need the usage of {{username}}

If someone is interested in the code,

Leave a Reply