Forivin
Forivin

Reputation: 15488

Ansible: Task structure of roles

I have 4 playbooks. 2 of them are deploying services on my target machines and 2 of them are removing them again. Now I want to put them in roles. But I'm not sure what the best-practice is.
The 2 deploy playbooks are doing the exact same thing only with different variables and templates. Same applies to the remove playbooks.

Atm my structure looks like this:

ansible.cfg
ssh_key
inventoryfile
group_vars
    ....
roles
    deployservicegroupA
       vars
           ...
       templates
           ...
       tasks
           main.yml (this file simply includes the two tasks right below)
           copy-service-templates.yml
           start-services.yml
    deployservicegroupB
       vars
           ...
       templates
           ...
       tasks
           main.yml (this file simply includes the two tasks right below)
           copy-service-templates.yml
           start-services.yml
    removeservicegroupA
       vars
           ...
       templates
           ...
       tasks
           main.yml (this file simply includes the two tasks right below)
           remove-services.yml
           cleanup.yml
    removeservicegroupB
       vars
           ...
       templates
           ...
       tasks
           main.yml (this file simply includes the two tasks right below)
           remove-services.yml
           cleanup.yml

Is this they way it was intended to be done by users?
I'm especially wondering about my tasks that do the exact same thing, but can be found in different roles. And also if I should include my tasks in the main.yml task file.

Upvotes: 0

Views: 340

Answers (1)

shaps
shaps

Reputation: 1179

As per your comment you are using a group for each service, you can use group_vars to specify the variables you want to use.

You can then merge the roles together, the only thing you will have to do is load specific templates based on the group you are running your play on.

Upvotes: 2

Related Questions