Re: custom functions or function macros
Mike Weilgart <[email protected]>
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Valentin, If you collect the promises you are writing into a bundle, you may find you don't need to use those functions over and over. Bundles can also be parameterized. However, they are NOT functions. There is no such thing as a user-defined function in CFEngine policy, and the functions that do exist should be thought of more as "helpers" than as imperative actions like you would find in C or Python or most other languages. CFEngine is declarative, not imperative. I'm not entirely sure why you would need to check if a hostname is resolvable in the context of writing CFEngine policy; possibly if you give more info on your use case, I (or someone else) could suggest a more idiomatic CFEngine solution. Incidentally, there is a great tutorial that Aleksey Tsalolikhin wrote a few years ago: https://www.softcover.io/read/72be7d4f/cf3/cfengine_100 It's for a slightly older version of CFEngine 3 than the most recent one, but I recommend it because it goes a long way toward helping you "think" in CFEngine, and approach problems and use cases in the manner best suited to a declarative language. Hope that helps. Best, —Mike Weilgart On Dec 6, 2021, at 7:23 AM, Valentin Kleibel <[email protected]> wrote: Hello, I recently came across situation where i need to use the same combination of functions over and over again. In my case it's to check if a hostname is resolvable: 'not( strcmp( host2ip( $(hostname) ), $(hostname) ) )' Is there any way to make this a custom function or macro that i can easily reuse? Thanks for your help, Valentin -- 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] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/e866d838-9568-4a42-a265-cc0e10058e6bn%40googlegroups.com <https://groups.google.com/d/msgid/help-cfengine/e866d838-9568-4a42-a265-cc0e10058e6bn%40googlegroups.com?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 on the web visit https://groups.google.com/d/msgid/help-cfengine/4AD6D73F-0F17-4109-9DDE-3C0E7E7FB7B3%40verticalsysadmin.com.