I'm using to fetch the status of the few services using ansible and generating the HTML output using ansible jinja template, I'm getting variable undefined or some other error,
Here I'm storing the values in the register module and then fetching those values in template, but it's not working
Jinja Template:
{% for network_switch in ['client'] %}
<tr>
<td>{{ hostvars[network_switch]['ansible_hostname'] }}</td>
<td>{{ hostvars[network_switch]['kernel.stdout'] }}</td>
<td>{{ hostvars[network_switch]['httpd.stdout'] }}</td>
</tr>
{% endfor %}
Playbook Details:
- name: Getting the OS Information
command: 'uname -r'
register: kernel
- name: Getting the OS Information
shell: "systemctl status sshd | grep -i active | awk '{print$3}'"
register: httpd
- name: create HTML report
template:
src: report.j2
dest: "{{ file_path }}"
delegate_to: localhost
run_once: true
Error:
FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: \"hostvars['client']\" is undefined"}