Switch Interface UP then playbook should end with error msg

26 views
Skip to first unread message

Akshay Jadhav

unread,
Dec 23, 2021, 1:49:07 AM12/23/21
to Ansible Project
Hi all,
I need a help from you guys for writing a play if Switch Interface UP then playbook should end with error msg using when condition. I am kind of new to ansible. So please help me out for writing this task.
Thank you in advance.

Dick Visser

unread,
Dec 23, 2021, 1:52:41 AM12/23/21
to ansible...@googlegroups.com
What does your playbook look like?

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b481d0ff-1160-4307-9e2d-3e1433079a02n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Akshay Jadhav

unread,
Dec 23, 2021, 5:54:42 AM12/23/21
to Ansible Project

   - name: show message if interface is not down
     fail:
      msg: "Interface is not down"
     when: {{ interface }}.operstatus == "up"
 
will this work?

Dick Visser

unread,
Dec 23, 2021, 6:00:49 AM12/23/21
to ansible...@googlegroups.com
Probably not, but you could have tried yourself?

Drop the moustaches as when conditions are already evaluated as jinja

Stefan Hornburg (Racke)

unread,
Dec 23, 2021, 8:29:49 AM12/23/21
to ansible...@googlegroups.com
On 23/12/2021 11:54, Akshay Jadhav wrote:
>
>    - name: show message if interface is not down
>      fail:
>       msg: "Interface is not down"
>      when: {{ interface }}.operstatus == "up"
>
> will this work?

Definitely not, that is pulled from thin air if you ask me.

Try that:

when: vars.get('ansible_' + interface).active

Note:

Gather facts saves the network interface information in separate variables (e.g. ansible_eth0) instead of a dict/list,
so accessing the info for a specific item is a bit awkward.

Regards
Racke

> On Thursday, 23 December 2021 at 12:22:41 UTC+5:30 dick....@geant.org wrote:
>
> What does your playbook look like?
>
> On Thu, 23 Dec 2021 at 07:49, Akshay Jadhav <aksha...@gmail.com> wrote:
>
> Hi all,
> I need a help from you guys for writing a play if Switch Interface UP then playbook should end with error msg using when condition. I am kind of new to ansible. So please help me out for writing this task.
> Thank you in advance.
>
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b481d0ff-1160-4307-9e2d-3e1433079a02n%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/b481d0ff-1160-4307-9e2d-3e1433079a02n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> Sent from a mobile device - please excuse the brevity, spelling and punctuation.
>
> --
> 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/1edeb012-822f-49a9-a58a-b6084ba583f1n%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/1edeb012-822f-49a9-a58a-b6084ba583f1n%40googlegroups.com?utm_medium=email&utm_source=footer>.


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


OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages