RAX modules and delegate_to directive.

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

Have you read http://docs.ansible.com/guide_rax.html ?