2

I'm trying to display some variables about the hosts using ansible gather facts. Here's the yml file

- name: setup users
  gather_facts: true
  hosts: hosts
  tasks:
    name: display stats after login
    template: 
      src: /stats.j2
      dest: /etc/motd
    become: true

Here's the jinja2 file

Arch: {{ hostvars[inventory_hostname]['ansible_architecture'] }}

Accoring to anisble -m setup the variable exits but I'm always getting an error that the variable is undefined.

1 Answer 1

0

You would use {{hostvars['inventory_hostname']['...']}}. But if you do not want to access informations from other hosts you could change your template (stats.j2) to

Arch: {{ansible_architecture}}
2
  • I tried both versions and still get the same error that the variable is undefined.
    – tactical77
    Jan 25, 2021 at 17:46
  • It actually works now don't really know what the problem was but thanks.
    – tactical77
    Jan 30, 2021 at 14:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .