# Ansible's philosophy about running playbooks against localhost and use lot of delegate\_to in roles

**URL:** <https://forum.ansible.com/t/ansibles-philosophy-about-running-playbooks-against-localhost-and-use-lot-of-delegate-to-in-roles/20253>\
**Category:** Ansible Project\
**Created:** [January 18, 2016, 2:16pm UTC](https://forum.ansible.com/t/ansibles-philosophy-about-running-playbooks-against-localhost-and-use-lot-of-delegate-to-in-roles/20253 "2016-01-18T14:16:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sylvain1](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Sylvain1](https://forum.ansible.com/u/Sylvain1)\
**Post date:** [January 18, 2016, 2:16pm UTC](https://forum.ansible.com/t/ansibles-philosophy-about-running-playbooks-against-localhost-and-use-lot-of-delegate-to-in-roles/20253/1 "2016-01-18T14:16:13Z")

</div>

Hi !

I’m currently thinking what is the best way to build a complete infrastructure based on Ansible 2.

For example, take an installation of WordPress which need Apache and MySQL :

1/ I have 3 standalones roles which uses for each task **delegate\_to** with a variable :

- role apache

- role mysql

- role wordpress (dependencies : apache & mysql)

2/ I have 1 playbook which call multiples times the wordpress role with differents variables (servers, instance name, …) for the differents WordPress instances. The host used to run the playbook is **localhost**.

The overall solution looks good, roles are decoupled, reusables and the maintenance will not be a nightmare.

But in the documentation (intro to playbooks), I’ve read that “the goal of a play is to map a group of hosts to some well defined roles” and what I do is to map forever to **localhost**.

Is my solution is acceptable in the Ansible’s philosophy ? My goal is not to thinking, virtual machine but services.

Best regards,

Sylvain

---

<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 19, 2016, 1:30am UTC](https://forum.ansible.com/t/ansibles-philosophy-about-running-playbooks-against-localhost-and-use-lot-of-delegate-to-in-roles/20253/2 "2016-01-19T01:30:18Z")

</div>

i would say that to make your roles more reusable, don't use  
delegate\_to but set the play to localhost or connection=local.

---

<div class="post-metadata">

**Author:** ![Sylvain1](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Sylvain1](https://forum.ansible.com/u/Sylvain1)\
**Post date:** [January 19, 2016, 11:20am UTC](https://forum.ansible.com/t/ansibles-philosophy-about-running-playbooks-against-localhost-and-use-lot-of-delegate-to-in-roles/20253/3 "2016-01-19T11:20:18Z")

</div>

Thanks for your reply.

My play run already on **localhost**. If I don’t use **delegate\_to** , this will be hard to make actions on servers.

My roles are parametrized to take server in parameters among others so my roles are already reusable but I’m ok to say that it will be more clean to suppress **delegate\_to** directives for each tasks in my roles.  
So I must find a way to respect my philosophy to think services and not servers : I want do know easily what’s the service’s dependancies (which servers ? which databases names ? which users ? and so on).

Another plan to follow the principe of “a play is to map a group of hosts to some well defined roles” :

- I remove **delegate\_to** from roles
- I specify in my playbook for each host, which roles and which params the service need

Like this, I must specify **apache** and **mysql** roles on my playbook so I no longer use dependancies in **roles/wordpress/meta/**.  
Too bad, It was a great usage of this functionnality I think.

If I disregard theses considerations and for one wordpress instance : why not ?  
But if I want more and know easily what is the service’s dependancies, I must make lot of cut and paste. It’s not nice (In first solution, I have only one line { role : wordpress ; db\_server : bdd1 , … }  
If I made one playbook for one instance, it will be more readable but there will be too copy and paste for me.

Have another point of view or idea to stay with Ansible’s philosophy ?

Sylvain

---

<div class="post-metadata">

**Author:** ![Sylvain1](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Sylvain1](https://forum.ansible.com/u/Sylvain1)\
**Post date:** [January 20, 2016, 6:01pm UTC](https://forum.ansible.com/t/ansibles-philosophy-about-running-playbooks-against-localhost-and-use-lot-of-delegate-to-in-roles/20253/4 "2016-01-20T18:01:51Z")

</div>

Nobody else ? ☹
