Hi
I was trying to make report for free space in vg, but I have a problems,
it's look like jinja doesn't like me::))
ansible_lvm
},
"vgs": {
"vg_root": {
"free_g": "0",
"num_lvs": "2",
"num_pvs": "1",
"size_g": "19.00"
},
"vgswap": {
"free_g": "1.50",
"num_lvs": "1",
"num_pvs": "1",
"size_g": "1.75"
},
"vgdata": {
"free_g": "1.80",
"num_lvs": "1",
"num_pvs": "1",
"size_g": "1.75"
- name: vg free
copy:
content: |
{% for vg in ansible_lvm %}
{{ vg.vgs }} {{ vg.free_g }} GB
{% endfor %}
dest: /tmp/vg-free-vgs
but it keep telling me that I didn't defined variable vgs: (The task
includes an option with an undefined variable. The error was: 'str object'
has no attribute 'vgs') .
Can you please help me once again with this? Thanks
On Sunday, January 24, 2021 at 1:55:13 PM UTC+1 [email protected] wrote:
> On 1/24/21 1:24 PM, j..r.. wrote:
> > what will be jinja template if I would like to create report only for /
> and /var partition? Or haw would I accomplish that?
> >
> > Thanks
> >
> > Regards
> >
>
> You have (at least) two options here.
>
> First with a if condition:
>
> {% for mt in ansible_mounts %}
> {% if mt.mount in ['/', '/var'] %}
> {{ mt.mount }}: {{ ( mt.size_available / ( 1024 | pow(3))) | round(2) }}
> GB free
> {% endif %}
> {% endfor %}
>
> Second with a filter on ansible mounts:
>
> {% for mt in (ansible_mounts | selectattr('mount', 'search', '^/(var)*$')
> | list) %}
> {{ mt.mount }}: {{ ( mt.size_available / ( 1024 | pow(3))) | round(2) }}
> GB free
> {% endfor %}
>
> If the partitions to report vary between host / groups use the first
> solution and replace ['/', '/var']
> with a variable, e.g.
>
> report_parts:
> - /
> - /var
>
> Regards
> Racke
>
> >
> >
> > On Sunday, January 24, 2021 at 10:17:24 AM UTC+1 [email protected]
> wrote:
> >
> > On 1/23/21 1:11 PM, j..r.. wrote:
> > > Thanks, this works great, can you explain me more what this jinja2
> template do especially:
> > >
> > > / ( 1024 | pow(3))) | round(2) }
> > >
> > > / ( 1024 | pow(3)) --> is this divide1024 three times? what is pow ?
> > > round(2) --> two decimal ?
> > >
> > > where can I get more jinja2 examples or tutorial?
> >
> > 1024 | pow(3) ... that is 1024³ = 1024 * 1024 * 1024 = 1 GB
> >
> > round ... rounds a number with optional decimals, so 10.445 | round(2)
> => 10.45.
> >
> > So we divide the available size by 1 GB and round it up. The parentheses
> are important
> > to process in the correct orders.
> >
> > I maintain a couple of filter examples at
> >
> https://wiki.linuxia.de/library/stefan-hornburg-racke-ansible-provisioning-en#text-amuse-label-filters
> > <
> https://wiki.linuxia.de/library/stefan-hornburg-racke-ansible-provisioning-en#text-amuse-label-filters
> >
> >
> > Regards
> > Racke
> >
> > >
> > > Thanks
> > > On Friday, January 22, 2021 at 8:39:35 PM UTC+1 [email protected]
> wrote:
> > >
> > > On 1/22/21 5:29 PM, j..r.. wrote:
> > > > Hi
> > > >
> > > > I would like to create report for free partition size under
> "ansible_mounts"
> > > >
> > > > "ansible_mounts": [
> > > > {
> > > > "block_available": 3911145,
> > > > "block_size": 4096,
> > > > "block_total": 4452864,
> > > > "block_used": 541719,
> > > > "device": "/dev/mapper/vg_root-lv_root",
> > > > "fstype": "xfs",
> > > > "inode_available": 8871855,
> > > > "inode_total": 8910848,
> > > > "inode_used": 38993,
> > > > * "mount": "/", *
> > > > "options":
> "rw,seclabel,relatime,attr2,inode64,noquota",
> > > > *"size_available": 16020049920, *
> > > > "size_total": 18238930944,
> > > > "uuid": "e2968252-bcd8-45ac-9604-714aa932deb9"
> > > > },
> > > > {
> > > > "block_available": 222270,
> > > > "block_size": 4096,
> > > > "block_total": 259584,
> > > > "block_used": 37314,
> > > > "device": "/dev/sda1",
> > > > "fstype": "xfs",
> > > > "inode_available": 523988,
> > > > "inode_total": 524288,
> > > > "inode_used": 300,
> > > > * "mount": "/boot", *
> > > > "options":
> "rw,seclabel,relatime,attr2,inode64,noquota",
> > > > *"size_available": 910417920, *
> > > > "size_total": 1063256064,
> > > > "uuid": "bcce38b2-0c6c-44aa-99be-20e3553d23ee"
> > > >
> > > >
> > > > how can I get variables for /, /var /boot and other partitions and
> create report like this in a file:
> > > > root: 10GB free
> > > > /boot: 800MB free
> > > > /var: 2GB free
> > > >
> > > > Thanks
> > >
> > > - copy:
> > > content: |
> > > {% for mt in ansible_mounts %}
> > > {{ mt.mount }}: {{ ( mt.size_available / ( 1024 | pow(3))) | round(2)
> }} GB free
> > > {% endfor %}
> > > dest:
> > > /tmp/freespace.txt
> > >
> > > This creates a report in /tmp/freespace.txt with the GB values with
> two decimal spaces.
> > > Distinguishing between GB and MB would be a bit more complicated.
> > >
> > > Regards
> > > Racke
> > >
> > >
> > >
> > > --
> > > Ecommerce and Linux consulting + Perl and web application programming.
> > > Debian and Sympa administration. Provisioning with Ansible.
> > >
> > > --
> > > 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] <mailto:
> [email protected]>.
> > > To view this discussion on the web visit
> > >
> https://groups.google.com/d/msgid/ansible-project/610532a8-4d79-4efc-850b-46b7d6de02dcn%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/610532a8-4d79-4efc-850b-46b7d6de02dcn%40googlegroups.com
> >
> > >
> > <
> https://groups.google.com/d/msgid/ansible-project/610532a8-4d79-4efc-850b-46b7d6de02dcn%40googlegroups.com?utm_medium=email&utm_source=footer
> > <
> https://groups.google.com/d/msgid/ansible-project/610532a8-4d79-4efc-850b-46b7d6de02dcn%40googlegroups.com?utm_medium=email&utm_source=footer
> >>.
> >
> >
> >
> > --
> > Ecommerce and Linux consulting + Perl and web application programming.
> > Debian and Sympa administration. Provisioning with Ansible.
> >
> > --
> > 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] <mailto:
> [email protected]>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/2b0b0b31-8f27-4d92-857d-253b54b86fadn%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/2b0b0b31-8f27-4d92-857d-253b54b86fadn%40googlegroups.com?utm_medium=email&utm_source=footer
> >.
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/062dea20-f549-4d89-a884-1796af1d56e5n%40googlegroups.com.