# haproxy.cfg.j2 and webservers facts values

**URL:** <https://forum.ansible.com/t/haproxy-cfg-j2-and-webservers-facts-values/13241>\
**Category:** Ansible Project\
**Created:** [August 1, 2013, 3:31pm UTC](https://forum.ansible.com/t/haproxy-cfg-j2-and-webservers-facts-values/13241 "2013-08-01T15:31:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [August 1, 2013, 3:31pm UTC](https://forum.ansible.com/t/haproxy-cfg-j2-and-webservers-facts-values/13241/1 "2013-08-01T15:31:12Z")

</div>

Hi all,

From the Ansible documentation examples I have setup my lamp deployment in an Amazon EC2 environment as bellow :

hosts.txt :

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [August 1, 2013, 4:14pm UTC](https://forum.ansible.com/t/haproxy-cfg-j2-and-webservers-facts-values/13241/2 "2013-08-01T16:14:14Z")

</div>

Take a look at setting up delegation:

[http://www.ansibleworks.com/docs/playbooks2.html#delegation](http://www.ansibleworks.com/docs/playbooks2.html#delegation)

What you’ll want to do is use delegate\_to to your proxy.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 1, 2013, 5:50pm UTC](https://forum.ansible.com/t/haproxy-cfg-j2-and-webservers-facts-values/13241/3 "2013-08-01T17:50:38Z")

</div>

Sure, what you can do is simply have a play at the top that includes the tag.

- hosts: all  
tasks:   
tag: mytag

# actual play goes here

And that will force fact gathering on all machines.

We’re looking to cache facts in 1.3 or early 1.4, hopefully 1.3.

---

<div class="post-metadata">

**Author:** ![Manuel\_Jimenez](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@Manuel\_Jimenez](https://forum.ansible.com/u/Manuel_Jimenez)\
**Post date:** [August 7, 2013, 8:55am UTC](https://forum.ansible.com/t/haproxy-cfg-j2-and-webservers-facts-values/13241/4 "2013-08-07T08:55:07Z")

</div>

Hello, I also have the same situation. I can’t use roles at the moment because every server has special configurations. And I need gather facts of some hosts to fill the configuration.

My hosts file.  
[server1-app]  
10.10.10.1

[server2-app]  
10.10.10.2

[server3-app]  
10.10.10.3

[server-app:children]  
server1-app  
server2-app  
server3-app

[server-ha]  
10.10.10.254

Then I have a playbook only for server-ha to configure haproxy:

---

<div class="post-metadata">

**Author:** ![Manuel\_Jimenez](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@Manuel\_Jimenez](https://forum.ansible.com/u/Manuel_Jimenez)\
**Post date:** [August 8, 2013, 6:25am UTC](https://forum.ansible.com/t/haproxy-cfg-j2-and-webservers-facts-values/13241/5 "2013-08-08T06:25:15Z")

</div>

Finally, I’ve got it working adding at the top in the ha-server.yml playbook

- hosts: server-app  
tasks:  
gather\_facts: True

- hosts: server-ha  
user: root

… rest stuff of playbook.

Thanks for all!

Manuel.

---

<div class="post-metadata">

**Author:** ![Phillip\_Gentry](https://avatars.discourse-cdn.com/v4/letter/p/90db22/32.png) [@Phillip\_Gentry](https://forum.ansible.com/u/Phillip_Gentry)\
**Post date:** [August 8, 2013, 5:14pm UTC](https://forum.ansible.com/t/haproxy-cfg-j2-and-webservers-facts-values/13241/6 "2013-08-08T17:14:24Z")

</div>

@OP:  
On the no attribute thing, I’m not sure what the answer is directly but you might try running the setup module with ansible on those machines to see what attributes your machines are providing. (ansible proxies -m setup)

On the second, I just separate each individual type of server into it’s own playbook, and then also have a playbook that runs them all (the big one pretty much never actually gets used right now because it just takes too long). Since all the code is in the roles anyway, it still leaves a very manageable root dir.

Of course when you do the proxies playbook, you will have to add a section that gathers facts from the other groups, but doesn’t run any tasks, like what Manuel has done. Otherwise the information for your webservers won’t be available to haproxy.
