Re: custom functions or function macros

"'Nick Anderson' via help-cfengine" <[email protected]>
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
=D I like that someone else said bundles are not functions, thanks Mike.
=D

As Mike noted, we don't yet have any way to define custom functions
(though we do have custom promise types now!) and none of our [existing
macros] speak to this kind of functionality, they are all more about
including or excluding a block, not for filling in the content of a
block with some referenced content..

If you are repeatedly using `not( strcmp( host2ip( $(hostname) ),
$(hostname) ) )' I think the typical approach would be to simply define
a class and use that.

,----
| bundle agent __main__
| {
|   vars:
|      "hostname" string => "localhost"; 
| 
|   classes:
|       "hostname_does_not_match_ip"
|         scope => "namespace", # Presumably we want to use this in other bundles
|         expression => not( strcmp( host2ip( $(hostname) ), $(hostname) ) );
| 
|   reports:
|       hostname_does_not_match_ip::
|         "hostname '$(hostname)' does not match to an ip address because '$(hostname)' does not match '$(with)'"
|           with => host2ip( $(hostname) );
| 
| }
`----
Listing 1: Example Policy

,----
| R: hostname 'localhost' does not match to an ip address because 'localhost' does not match '127.0.0.1'
`----


But, maybe you have some other reason why you are using the nested
functions calls repeatedly instead of using them to set a class once.


[existing macros]
<https://docs.cfengine.com/docs/3.18/reference-macros.html>

-- 
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 on the web visit https://groups.google.com/d/msgid/help-cfengine/87a6h8mpxv.fsf%40northern.tech.

-- 
Nick Anderson | Doer of Things | (+1) 785-550-1767 | https://northern.tech

-- 
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 on the web visit https://groups.google.com/d/msgid/help-cfengine/87a6h8mpxv.fsf%40northern.tech.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.