Collecting and filtering remote facts

Hello

Let me start with the use case. I have to retrieve the filename pointed by a symlink, say /etc/current → /etc/version-1.0 and determine if this filename is the same across a bunch of nodes.

I figure I have to do two things:

  1. Use file module, and get the filename, and use set_fact to set “version_number” fact on each node.
  2. Loop through the facts for each node, and keep appending a set (using union with the “version_number” fact
  3. If the final set is greater than 1 there is a mistmach in version, if not I can display that version_number.

This is how I attempted to do it :

`

For someone with this same problem, this is how I solved it :

  1. First play, set_fact the link target on all hosts
  2. Second play, use a template and generate a list of link targets using the facts set above. This is done using hostvars in jinja.
  3. Use include_vars to include the generated template

Example playbook : https://gist.github.com/raags/0f2089ec1208617b86d8