Gathering Facts about Hosts Not Included in the Play

I’m attempting to setup an nfsserver and nfsclients in a playbook. These are my host names:

appserver-1
appserver-2
appserver-3

I want the NFS server to exist on appserver-1 and then mount the folder on appserver-2 and 3. Here are my plays:

hosts: appserver-1
vars:

  • nfs_device: eth2
    roles:
  • nfsserver

hosts: appserver*:!appserver-1
roles:

  • nfsclient

Within the nfsserver role, I export this fact:

  • name: Export the nfsserver IP fact
    set_fact:
    nfsserver_host: “{{ ansible_{{ nfs_device }}[‘ipv4’][‘address’] }}”

And then I’m attempting to use that in the nfsclient role:

  • name: configure /etc/fstab on clients
    mount: name=“{{ nfsclient_mountpoint }}” src=“{{ nfsserver_host }}:{{ nfsserver_mountpoint }}” fstype=nfs opts=“{{ nfsoptions }}” state=mounted

When I run with -v, I get a the following on the nfs server:

All you need do here is start a baby-play before that talks to the hosts:

  • hosts: all
    tasks:

  • hosts: somehosts
    tasks:

And that will gather them.

Fact caching in Ansible from prior runs is something we’re interested in doing for a future release.

This solution works fine (task: is not even usefull), but
unfortunately prevents use of the --limit argument because facts may
not be gathered again, and some tasks will failed.

The inability to use retry files is quite frustrating.

So despite this trick, I really hope fact caching is coming soon :slight_smile:

Le 13/10/10 20:13, Michael DeHaan claviotta :

  • hosts: localhost
    gather_facts: False
    tasks:
  • setup:
    delegate_to: “{{item}}”
    #with_items: [ ‘host1’, ‘host2’ ]
    with_items: groups[‘qa’]

“task: is not even usefull”. It’s “tasks”, and it’s useful to lots of people :slight_smile:

I’m not sure what you mean about not being able to use retry files either.

I do understand what you are saying about --limit and fact gathering, which is why we want to cache facts in a future release.