- name: Gather facts from host and print variables hosts: all gather_facts: yes tasks: - name: Print ansible facts tags: facts debug: var: ansible_facts - name: Print all variables tags: vars debug: var: vars - name: Print variable value tags: var when: var_name is defined debug: msg: "{{ var_name }}: {{ lookup('vars', var_name, default='undefined') }}"