Re: Found out all of the nics cards on a system

"'Nick Anderson' via help-cfengine" <[email protected]> Wed, 20 Nov 2024 22:34:34 -0600
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <CAE46pPsQk3SvJ49hxEX+mthVVC-jTbnChNoyYwLkKKFW+RSX1A@mail.gmail.com>
Without running it myself and inspecting the details...

You don't see reports for this promise:
      "Value of sys_interfaces $(sys_interfaces)";

Because sys_interfaces isn't defined.

It's not defined because getindices() on a list has no result. I think it
would make sense that it return the numeric positions of the elements,
basically length - 1 and there might even be a ticket with that request,
but it's a very niche case when you could just iterate on sys.interfaces.
The docs do indicate the function takes an array (classic associative), or
data container.
https://docs.cfengine.com/docs/3.24/reference-functions-getindices.html

You can copy the list like this:

   "sys_interfaces" slist => { @(sys.interfaces) };




On Wed, Nov 20, 2024, 4:05 PM Jerome Verleyen <[email protected]>
wrote:

> Le 19/11/2024 à 12:51, 'Nick Anderson' via help-cfengine a écrit :
>
> What i need now is to get the list of all the networds cards present in
> one system, to configure specific one on an ipv4 network. I do use the
> sys.interfaces variables. But this get me back uniquely the configured
> interfaces, not alla of then.
>
> Do any of the sys vars contain what you are looking for (cf-promises
> --show-vars)
>
> Perhaps sys.interfaces_data?
>
> bundle agent __main__{
>      vars:
>         "sys_interfaces_data_keys"
>           slist => getindices( "sys.interfaces_data" );
>
>       reports:
>           "$(sys_interfaces_data_keys)";}
>
> R: lo
> R: wlp0s20f3
> R: virbr0
> R: br-a7d465b9949b
> R: docker0
> R: enx0892048803e7
> R: enx5cff35c6864b
> R: vboxnet0
> R: tun0
>
> Dear Nick and others
>
> Thank's for answer me so quickly. I do some test to check  out your code.
>
> You're right in using cf-promises command to get back this variables.
>
> I do a bundle to test it, and have some good results:
>
> bundle agent network
> {
>
>   vars:
>       "sys_interfaces" slist => getindices("sys.interfaces");
>
>       "sys_interfaces_data_keys" slist => getindices(
> "sys.interfaces_data" );
>
>       "sys_ipv4" slist => getindices("sys.ipv4");
>
>   reports:
>
>     any::
>       "Value of sys_interfaces $(sys_interfaces)";
>
>       "Value of sys_interfaces_data $(sys_interfaces_data_keys)";
>
>       "value of sys_ipv4: $(sys_ipv4)";
>
> }
>
> That get me this report:
>
>
> R: Value of sys_interfaces_data lo
> R: Value of sys_interfaces_data enp1s0
> R: Value of sys_interfaces_data enp7s0
> R: Value of sys_interfaces_data enp8s0
> R: Value of sys_interfaces_data virbr0
> R: value of sys_ipv4: enp8s0
> R: value of sys_ipv4: lo
> R: value of sys_ipv4: enp7s0
> R: value of sys_ipv4: virbr0
> R: value of sys_ipv4: enp1s0
>
> So, "sys.interfaces_data" is the good variable. But i've got an issue that
> i could no explain: Why could i no get the list of the sys.interfaces name?
> With the variable "sys_interfaces", I've get anything, as show before.
>
> But if i wirte directly in report as this:
>
>   reports:
>
>     any::
>       "Value of sys_interfaces $(sys.interfaces)";
>
> I get back this report:
>
> R: Value of sys_interfaces enp1s0
> R: Value of sys_interfaces enp7s0
> R: Value of sys_interfaces enp8s0
> R: Value of sys_interfaces virbr0
>
> I could not understand why the variable definition of sys_interfaces get
> back a null list...
>
> Hope that someone could help me.
>
> Regards
>
>
>
> --
> -- Jérôme
> Les jeunes gens voudraient être fidèles et ne le sont pas.
> Les vieux voudraient être infidèles et ne le peuvent plus.
> 	(Oscar Wilde)
>
> --
> You received this message because you are subscribed to the Google Groups
> "help-cfengine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/help-cfengine/f24823e8-919b-4820-b28f-236d67543391%40ibt.unam.mx
> <https://groups.google.com/d/msgid/help-cfengine/f24823e8-919b-4820-b28f-236d67543391%40ibt.unam.mx?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/help-cfengine/CAE46pPsQk3SvJ49hxEX%2BmthVVC-jTbnChNoyYwLkKKFW%2BRSX1A%40mail.gmail.com.