On 4/20/21 3:07 PM, Vikram S wrote: > Hi Racke, > > Thanks for the syntax, it is giving an output close to what i want but not > exactly the numbers i want to extract.
Hello Vikram,
that is because you didn't give the exact input, aka the contents of the
show_space variable.
Regards
Racke
>
> *OUTPUT IN DEVICE:*
> SWITCH#sh flash: | i bytes
> 122185728 bytes total (48700416 bytes free)
>
> *MY SCRIPT:*
> tasks:
> - name: GATHER MASTER FLASH FREE SPACE
> ios_command:
> commands: "show flash: | i bytes"
>
> register: show_space
>
> - debug:
> msg: "{{ show_space | regex_findall('\\d+')
| last }}"
>
> *ANSIBLE OUTPUT:*
> TASK [debug]
> ******************************************************************************************************************************************************************************************************
> ok: [TEST2960] => {
> "msg": "3"
>
> If i give the script without the last keyword, below is output:
> - debug:
> msg: "{{ show_space | regex_findall('\\d+') }}"
>
> TASK [debug]
> ******************************************************************************************************************************************************************************************************
> ok: [TEST2960] => {
> "msg": [
> "122185728",
> "48700416",
> "122185728",
> "48700416",
> "3"
> ]
>
> So how can the syntax be modified such that i get only '48700416' in output?
> I then plan to 'int' filter to convert it
> into a integer so that i can then compare it againt a value.
>
> Thanks,
> Vikram
> On Tuesday, 20 April, 2021 at 6:16:08 pm UTC+5:30 [email protected] wrote:
>
> On 4/20/21 2:16 PM, Vikram S wrote:
> > Hi Racke,
> >
> > I am not sure if ansible_mounts may help me. Reason is in a stacked
> cisco switch, 'ansible_net_filesystems_info' of
> > ios_facts module only shows free space of master switch. It doesn't
> show space of member switches. But I need to
> write a
> > script that will check for certain amt of free space in EVERY member
> switch before copying ios image.
> >
> > So i thought of using regex to extract the number and use int filter to
> convfert it into a integer acheive my objective.
> > Can you please give me sample regex syntax?
> >
> > *command in cli: sh flash2:*
> >
> > *data i want to use regex: 122185728 bytes total (9308672 bytes free)*
> > *
> > *
> > Thanks,
> > Vikram
>
> Hello Vikram,
>
> this should help you to get the second number from your string:
>
> - debug:
> msg: "{{ diskspace_string | regex_findall('\\d+') | last }}"
> vars:
> diskspace_string: '122185728 bytes total (9308672 bytes free)'
>
> Regards
> Racke
>
> >
> > On Tuesday, 20 April, 2021 at 5:27:11 pm UTC+5:30 [email protected]
> wrote:
> >
> > On 4/20/21 12:17 PM, Vikram S wrote:
> > > Hi,
> > >
> > > I went through ansible documentation for regex filter and it's
> various example. But please excuse my
> incomprehension,
> > > iam stuck on using regex to extract the integers.
> > >
> > > Below is the output on which i want to use regex. I want to filter
> out only '48700416' and leave out everything
> > else and
> > > then use 'int' filter on it so that i can then compare it against
> a particular number. Can you please give a sample
> > > regex syntax to achieve this?
> > >
> > > *122185728 bytes total (48700416 bytes free)*
> > > *
> > > *
> > > Thanks,
> > > Vikram
> >
> > Hello Vikram,
> >
> > if you are talking about diskspace, you can use the ansible_mounts
> variable, e.g.
> >
> > - debug
> > msg: |
> > {% for mt in ansible_mounts %}
> > {{ mt.mount }}: {{ ( mt.size_available / ( 1024 | pow(3))) | round(2)
> }} GB free
> > {% endfor %}
> >
> > Regards
> > Racke
> >
> > >
> > >
> > >
> > >
> > > --
> > > 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/2999c167-454e-4d35-a198-a71e515053fcn%40googlegroups.com
>
> <https://groups.google.com/d/msgid/ansible-project/2999c167-454e-4d35-a198-a71e515053fcn%40googlegroups.com>
> >
> <https://groups.google.com/d/msgid/ansible-project/2999c167-454e-4d35-a198-a71e515053fcn%40googlegroups.com
>
> <https://groups.google.com/d/msgid/ansible-project/2999c167-454e-4d35-a198-a71e515053fcn%40googlegroups.com>>
> > >
> >
>
> <https://groups.google.com/d/msgid/ansible-project/2999c167-454e-4d35-a198-a71e515053fcn%40googlegroups.com?utm_medium=email&utm_source=footer
>
> <https://groups.google.com/d/msgid/ansible-project/2999c167-454e-4d35-a198-a71e515053fcn%40googlegroups.com?utm_medium=email&utm_source=footer>
>
> >
>
> <https://groups.google.com/d/msgid/ansible-project/2999c167-454e-4d35-a198-a71e515053fcn%40googlegroups.com?utm_medium=email&utm_source=footer
>
> <https://groups.google.com/d/msgid/ansible-project/2999c167-454e-4d35-a198-a71e515053fcn%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/ba7ffa19-85da-4da6-8142-c12ac066cbd5n%40googlegroups.com
>
> <https://groups.google.com/d/msgid/ansible-project/ba7ffa19-85da-4da6-8142-c12ac066cbd5n%40googlegroups.com>
> >
>
> <https://groups.google.com/d/msgid/ansible-project/ba7ffa19-85da-4da6-8142-c12ac066cbd5n%40googlegroups.com?utm_medium=email&utm_source=footer
>
> <https://groups.google.com/d/msgid/ansible-project/ba7ffa19-85da-4da6-8142-c12ac066cbd5n%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/06771fa8-72ef-4f52-8cb0-f13515fc72can%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/06771fa8-72ef-4f52-8cb0-f13515fc72can%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/964e573f-0dbe-98e4-37d9-1b634be90079%40linuxia.de.
OpenPGP_signature
Description: OpenPGP digital signature
