# RAX modules and delegate\_to directive.

**URL:** <https://forum.ansible.com/t/rax-modules-and-delegate-to-directive/15375>\
**Category:** Ansible Project\
**Created:** [May 30, 2014, 1:07pm UTC](https://forum.ansible.com/t/rax-modules-and-delegate-to-directive/15375 "2014-05-30T13:07:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin\_Praczko](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Marcin\_Praczko](https://forum.ansible.com/u/Marcin_Praczko)\
**Post date:** [May 30, 2014, 1:07pm UTC](https://forum.ansible.com/t/rax-modules-and-delegate-to-directive/15375/1 "2014-05-30T13:07:53Z")

</div>

Hello.

I would like to ask for hint related with following challange.

- Gather details about hosts (external IP for example) from RackSpace-Cloud with RAX\_modules
- Generate configuration for monitoring server related with RS-images.

So I have following setup:

- Remote VMs in RackSpace (RS) Cloud - which are behind NAT - so ansible facts gather internal IP
- Remote VM with monitoring system
- Local VM for running ansible.

I’ve manged to do:

- Gather facts from RS-Cloud VMs - for example partiions, etc
- Gather external IP from RS with RAX modules.

**Challnage:**  
How to force run delegate\_to on monitoring system to generate correct nagios configuation with valid external VM per host.

**Following Ansible documenation I have following playbook:**

`

# Gather details about RS

- name: RS-Cloud-VMs | Gather info about servers  
hosts: www  
connection: local  
gather\_facts: False

tasks:

- { include: roles/rax/tasks/gather\_info\_about\_nodes.yml, rax\_credentials: ‘files/rax/terr01.cfg’, rax\_region: DFW }
- include: roles/monitoring-server/tasks/generate\_nagios\_hostcfg.yml

`

**And task to generate nagios hostcfg looks:**

`

- name: Monitoring-Server | Generate main host files for node  
template: src={{ item }}.j2 dest=/path/to/file/{{ item }}-{{ ansible\_fqdn }}.cfg  
owner=ssh\_login group=users mode=0644  
delegate\_to: monitoring  
with\_items:
- host

`

As you can see connection for Playbook is ‘local’ as recommended on your documentation, task is doing delegate\_to remote monitoring host, however ansible is connecting with local host (forced by connection: local).

Could you let me know what is a best practice to achieve this, please?  
Especially that:

- Some VMs (in RS cloud) are behind NAT so ansible is able only gather internal IP
- Have to use rax module to get info about RS VMs with external IP.

The only one solution which comes to me is now:

- Generate required files locally
- Use rsync module later on monitoring system.

Not quite happy with this solution, but maybe will be the fastests.

Best regards,  
Marcin Praczko

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 31, 2014, 4:18pm UTC](https://forum.ansible.com/t/rax-modules-and-delegate-to-directive/15375/2 "2014-05-31T16:18:41Z")

</div>

Have you read [http://docs.ansible.com/guide\_rax.html](http://docs.ansible.com/guide_rax.html) ?
