Im using Ansible 1.2 latest dev release and trying the new feature of roles in order to migrate all of our infrastructure code from a specific vendor cloud manager to Ansible. In our existing infrastructure we use “templates” that are a set of scripts and specific variable values in order to deploy a server (web/ app/ proxy etc…) .
After looking at the documentation and Ansible best practice the current directory tree we have at the moment is :
roles/
└── db
├── tsaks
│ ├── mysql.yml
└── proxy
└── web
└── common
├── handlers
│ ├── all.yml
├── templates
├── vars
├── tasks
│ ├── ssh_users.yml
│ ├── monitoring.yml
If my understanding is correct, the template concept we were using before in Ansbile are achieved with the “roles” feature. The common role should be applied to ALL servers and consist of configuration regarding installing ssh keys & the monitoring agent. For the DB tier we want all common tasks to be applied + all tasks for the db role right ? if that’s the case I’m having problems executing my tasks using the role feature :
You will want to create a common/tasks/main.yml file which will be run when include the common role from your top-level playbook. From there you can include other playbooks if needed.
Thanks John, that seems to work. I was trying before with “include:” .
Regarding the vars and handlers files I have available in roles/common/vars/ roles/common/handlers/ needed by my tasks in roles/common/tasks/ , where is it best to define them? inside the master playbook (test.yml) or in the main.yml ? what’s the correct syntax ? do I need to use relative or absolute path ?
Thank you Michael, the examples you paste are very helpful but I can’t find where are you using the vars ? Why do you have a group_vars and don’t have defined a vars directory for every role ?