Hi guys,

Struggling with something that I'd really appreciate some help with.

I'm putting together a little role to handle rsnapshot configuration.
At the end of a template, I've got a for loop that's supposed to iterate 
over every host in our inventory (encompassed by the group 'servers'), look 
up their FQDN, and place their configuration in the file.

To do so, I'm wanting to leverage fact lookup. The idea is that there is 
some "dummy" job that runs on 'all' hosts, then the rsnapshot role is 
applied to the group 'rsnapshot_servers' using the facts gathered from this 
"dummy" job.

I've taken a couple approaches and just cannot seem to get this to work.

Here's the approach I'm taking:

Here's the playbook I'm using:
---
- hosts: servers
  tasks: # gather facts

- hosts: rsnapshot_servers
  roles:
    - rsnapshot

Here's the task this issue concerns:
  - name: Deploy rsnapshot configuration
    template:
      src: rsnapshot.conf.j2
      dest: /etc/rsnapshot.conf
      owner: root
      group: root
      mode: 0644
      validate: 'rsnapshot -c %s configtest'

And here's the block of Jinja2 in the above template that's supposed to be 
populating the file:
{% for host in groups['servers'] %}
backup {{ rsnapshot_remote_user }}@{{ hostvars[host]['ansible_fqdn'] }}:/
some/dir/    {{ host }}/
{% endfor %}

This fails with the following message:
TASK [rsnapshot : Deploy rsnapshot configuration] 
******************************
fatal: [my.host]: FAILED! => {"changed": false, "failed": true, "msg": 
"AnsibleUndefinedVariable: 
'dict object' has no attribute 'ansible_fqdn'"}


If I change the playbook target and the Jinja for loop to just target 
'rsnapshot_servers' (where the template task is running), this works with 
no problem. This leads me to believe that the facts are not being made 
available for this task.
Running the above playbook, I can confirm that 'setup' is run on all 
systems in the 'servers' group, so fact gathering should be working with no 
issues.

I've tried combinations of setting the playbook scope to 'servers' and 
using 'run_once'/'delegate_to'/'delegate_facts' to see if I can get the 
task to effectively be looking at all 'servers' systems, but it didn't work.

Does anyone have any idea how I can achieve this?
I need to populate this file with facts about systems from the inventory.

I'll also be introducing some other lookups into the for loop - but I need 
to at least tackle this first.

Thanks in advance for any help on this, it's greatly appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/22b75869-bcc8-4fe7-bda7-fd18ecf3aecb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to