When conditional does not work with ios_config module, please help

18 views
Skip to first unread message

Vikram S

unread,
Apr 11, 2021, 9:25:33 AM4/11/21
to Ansible Project
Hi,

I have written the below script to check if packages.conf has been updated (by checking it's date) in flash and if so, to set it as boot statement for switch. But ansible does not seem to consider the when conditional at all. It sets the boot statement regardless of whether the condition matches or not.
But below 'when' syntax works for ios_command module. Should i modify the syntax or am i writing it wrong?


 - name: GATHER PACKAGES.CONF FILE INFO IN FLASH
      ios_command:
        commands: "show flash: | i packages.conf"

      register: show_flash_packages

    - name: ADD PACKAGES.CONF AS BOOT STATEMENT WHEN THIS FILE IS UPDATED
      ios_config:
        lines:
          - boot system flash:packages.conf
      when:  
        - "'Apr 09 2021' in show_flash_packages.stdout[0] or
          'Apr 10 2021' in show_flash_packages.stdout[0]"

Thanks,
Vikram

Stefan Hornburg (Racke)

unread,
Apr 11, 2021, 9:33:17 AM4/11/21
to ansible...@googlegroups.com
Looks like you confused stdout_lines with stdout.

stdout is a string and so stdout[0] is the first character of stdout.

Regards
Racke

>
> Thanks,
> Vikram
>
> --
> 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-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/ea53769d-3763-41ab-9e3b-fc267dc16d64n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/ea53769d-3763-41ab-9e3b-fc267dc16d64n%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

OpenPGP_signature

Vikram S

unread,
Apr 11, 2021, 9:40:09 AM4/11/21
to Ansible Project
Hi Racke,

I have been told the same thing earlier as you said now and i have also tested. When i give "'Apr 09 2021' in show_flash_packages.stdout[0]", it seems to check the entire string and not just the first character.  
I give the exact when syntax with ios_command module and other modules and it works and it checks the entire string. Porblem with ios_config module is that it doesn't even seem to check the 1st character, but it simply seems to ignore the when conditional itself.

Are you saying that if i were to give it as below, it should work? I will double check again anyways.....

 - name: ADD PACKAGES.CONF AS BOOT STATEMENT WHEN THIS FILE IS UPDATED
      ios_config:
        lines:
          - boot system flash:packages.conf
      when:  
        - "'Apr 09 2021' in show_flash_packages.stdout or
          'Apr 10 2021' in show_flash_packages.stdout"

Thanks,
Vikram

Stefan Hornburg (Racke)

unread,
Apr 11, 2021, 9:56:01 AM4/11/21
to ansible...@googlegroups.com
On 4/11/21 3:40 PM, Vikram S wrote:
> Hi Racke,
>
> I have been told the same thing earlier as you said now and i have also
tested. When i give "'Apr 09 2021' in
> show_flash_packages.stdout[0]", it seems to check the entire string and
not just the first character.  
> I give the exact when syntax with ios_command module and other modules and it works and it checks the entire string.
> Porblem with ios_config module is that it doesn't even seem to check the 1st character, but it simply seems to ignore
> the when conditional itself.
>
> Are you saying that if i were to give it as below, it should work? I will double check again anyways.....
>
>  - name: ADD PACKAGES.CONF AS BOOT STATEMENT WHEN THIS FILE IS UPDATED
>       ios_config:
>         lines:
>           - boot system flash:packages.conf
>       when:  
>         - "'Apr 09 2021' in show_flash_packages.stdout or
>           'Apr 10 2021' in show_flash_packages.stdout"
>
> Thanks,
> Vikram

Can't be sure that this works as you didn't show the actual contents of show_flash_packages.stdout and especially where
it comes from.

So please include sufficient information in your next posts.

Regards
Racke
> <https://groups.google.com/d/msgid/ansible-project/ea53769d-3763-41ab-9e3b-fc267dc16d64n%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/ea53769d-3763-41ab-9e3b-fc267dc16d64n%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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/55af80c5-0704-40df-8b9d-21fc526260cfn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/55af80c5-0704-40df-8b9d-21fc526260cfn%40googlegroups.com?utm_medium=email&utm_source=footer>.
OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages