# How to handle services with associated data changing with time ?

**URL:** <https://forum.ansible.com/t/how-to-handle-services-with-associated-data-changing-with-time/20290>\
**Category:** Ansible Project\
**Created:** [January 20, 2016, 2:12pm UTC](https://forum.ansible.com/t/how-to-handle-services-with-associated-data-changing-with-time/20290 "2016-01-20T14:12:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christophe\_Meessen](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@Christophe\_Meessen](https://forum.ansible.com/u/Christophe_Meessen)\
**Post date:** [January 20, 2016, 2:12pm UTC](https://forum.ansible.com/t/how-to-handle-services-with-associated-data-changing-with-time/20290/1 "2016-01-20T14:12:29Z")

</div>

Apparently I need the concept of method or specific action on a role and I don’t how to implement it.

Consider a service with associated data changing in time on a remote host.

I need to perform three distinct actions on this service.

1. install or update to code and configuration
2. backup the associated data
3. restore the associated data from the backup

All three actions can be implemented by ansible.

But I don’t see how to pack them in one role. This is because (as I understood) invoking a role executes only one action defined in roles/X/tasks/main.yml.

That’s Ok for Install let say. But how could I add the set of tasks to do a backup or a restore ?

I thought we could use tags for that, but the problem is that by default (without specifying a tag on the playbook invocation) the special tag ‘all’ is used which result in executing all tasks. This would be a mess if the install, backup and restore tasks are all called if the user forgot to specify a tag.

One thing that could save my day is if it was possible to define a default tag different from ‘all’ in the ansible configuration ? I could the define the default tag ass ‘install’ or ‘install,config’ that will ensure that the tasks tagged as ‘backup’ or ‘restore’ are not executed.  
I couldn’t find such an option in the ansible configure documentation.

Otherwise is there a solution with the existing code ?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 20, 2016, 2:18pm UTC](https://forum.ansible.com/t/how-to-handle-services-with-associated-data-changing-with-time/20290/2 "2016-01-20T14:18:07Z")

</div>

> But I don't see how to pack them in one role. This is because (as I  
> understood) invoking a role executes only one action defined in  
> roles/X/tasks/main.yml.

not true, all tasks defined in main.yml get executed.

---

<div class="post-metadata">

**Author:** ![Christophe\_Meessen](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@Christophe\_Meessen](https://forum.ansible.com/u/Christophe_Meessen)\
**Post date:** [January 20, 2016, 2:38pm UTC](https://forum.ansible.com/t/how-to-handle-services-with-associated-data-changing-with-time/20290/3 "2016-01-20T14:38:44Z")

</div>

Yes sorry. That was what I mean. There is only one file main.yml that is always invoked and all tasks in it are executed.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 20, 2016, 2:39pm UTC](https://forum.ansible.com/t/how-to-handle-services-with-associated-data-changing-with-time/20290/4 "2016-01-20T14:39:57Z")

</div>

tasks in that file can be conditional, you can also have includes

---

<div class="post-metadata">

**Author:** ![Christophe\_Meessen](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@Christophe\_Meessen](https://forum.ansible.com/u/Christophe_Meessen)\
**Post date:** [January 20, 2016, 2:42pm UTC](https://forum.ansible.com/t/how-to-handle-services-with-associated-data-changing-with-time/20290/5 "2016-01-20T14:42:10Z")

</div>

Apparently I’m not the first to ask this. I just found this stackoverfow question asking the exact same thing.

[http://stackoverflow.com/questions/28789912/ansible-default-explicit-tags](http://stackoverflow.com/questions/28789912/ansible-default-explicit-tags)

It looks like allowing to override the default value of tags command line argument in the ansible configuration would be the simplest solution.
