Re: [ansible-project] Generate HTML Table from Ansible Inventory File

2020-09-02 Thread Vladimir Botka
On Wed, 2 Sep 2020 07:17:42 -0700 (PDT)
Xinhuan Zheng  wrote:

> ... if I want to reference all hosts in a 
> group, should I use
>
> {% for host in groups[group] %}

If "group" is the name of the group then use

  {% for host in groups['group'] %}

or, simply

  {% for host in groups.group %}

If "group" is the variable with the name of the group use

  {% for host in groups[group] %}


-- 
Vladimir Botka

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200902174531.1626a673%40gmail.com.


pgpSPtXVVOIBM.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Generate HTML Table from Ansible Inventory File

2020-08-28 Thread Vladimir Botka
On Fri, 28 Aug 2020 11:56:09 -0700 (PDT)
Xinhuan Zheng  wrote:

> [group1]
> server1.example.com
> server2.example.com
> 
> [group2]
> server3.example.com
> server4.example.com
> 
> [group1:vars]
> field1=a1
> field2=a2
> 
> [group2:vars]
> field1=a3
> field2=a4
>   
> server1.example.coma1a2
> server2.example.coma1a2
> server3.example.coma3a4
> server4.example.coma4a4

The playbook

  - hosts: all
tasks:
  - template:
  src: table.html.j2
  dest: table.html
delegate_to: localhost
run_once: true

and the template 
https://gist.github.com/vbotka/a43e33f2a2951ef434f72ebd98a9eb3e

  shell> cat table.html.j2
  {% for host in ansible_play_hosts %}
  {{ host }} {{ hostvars[host]['field1'] }} {{
hostvars[host]['field2'] }}
  {% endfor %}

give

  shell> cat table.html
  server1.example.com a1 a2
  server2.example.com a1 a2
  server3.example.com a3 a4
  server4.example.com a3 a4

Add the html code to the template. See "Jinja"
https://jinja.palletsprojects.com/en/2.11.x/en/

-- 
Vladimir Botka

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200828220637.513bd1a2%40gmail.com.


pgp7zer48piD1.pgp
Description: OpenPGP digital signature