How to compare two strings/Arrays

11 views
Skip to first unread message

Abhishek singh

unread,
Jan 28, 2019, 4:35:23 PM1/28/19
to Puppet Users
Hello Group,

I am trying to use facts like interfaces and based on the available interfaces perform  a common task.

Please help me out for below:

1. How  strings from core facts and local variable can be compared?

For example if interfaces has "eth0, lo, .." and i want to match from it.


1. if ('lo' in $facts['interfaces'])     # it is not working but also no validation error.



2.    if  ! ($facts['interfaces'] in [ 'lo', 'ens160' ])   # it is not working but also no validation error.
       

is it possible to put a condition on facts existence itself? 

like if ipaddress_eth0 is then perform action from code/enter in loop.


Please help me out.
Also, Please suggest any links for future understanding.

Thanks.

steven.p...@onyxpoint.com

unread,
Jan 29, 2019, 11:42:42 AM1/29/19
to Puppet Users
$facts['interfaces'] is a string, not an array.  For an array of interface names, either use $facts['interfaces'].split(',') or $facts['networking']['interfaces'].keys().

Other than that, your logic should work fine.

Abhishek singh

unread,
Jan 29, 2019, 11:48:19 AM1/29/19
to puppet...@googlegroups.com
Thanks Steven.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/d2191cce-ed39-4e01-a3ad-e6cb363dcd26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages