Movatterモバイル変換


[0]ホーム

URL:


CFEngine documentation homepage

hostrange

Suggest changes
Table of contents

Prototype:hostrange(prefix, range)

Return type:boolean

Description: Returns whether the unqualified name of the current host liesin therange of enumerated hostnames specified withprefix.

This is a pattern matching function for non-regular (enumerated)expressions. Therange specification is in the formatA-B (using a minuscharacter-) whereA andB are decimal integers, optionally prefixed withzeroes (e.g.01). The unqualified name of the current host used in thisfunction is the same as the contents of thesys.uqhostvariable. The function is using integer comparison onrange and the lastnumeric part of the unqualified host name and string comparison ofprefix(lowercase) with the part of the unqualified host name until the last numericpart.

Arguments:

  • prefix:string - Hostname prefix - in the range:.*
  • range:string - Enumerated range - in the range:.*

Example:

code
bundleagentmain{vars:"range"string=>"1-32";"hostname_f"string=>execresult("hostname -f",useshell);"hostname_s"string=>execresult("hostname -s",useshell);"hostname"string=>execresult("hostname",useshell);classes:"hostgroup_alpha_no_leading_zeros"expression=>hostrange("host",$(range));"hostgroup_alpha_leading_zeros"expression=>hostrange("host","00$(range)");"hostgroup_alpha_UPPERCASE_prefix"expression=>hostrange("HOST","0$(range)");reports:"sys.fqhost = '$(sys.fqhost)'";"sys.uqhost = '$(sys.uqhost)'";"hostname -f = '$(hostname_f)'";"hostname -s = '$(hostname_s)'";"hostname = '$(hostname)'";hostgroup_alpha_no_leading_zeros::"This host is within the alpha host group range (host$(range))";hostgroup_alpha_leading_zeros::"This host is within the alpha host group range (host00$(range)) (NOTE: Leading zeros and prefix capitalization is insignificant)";hostgroup_alpha_UPPERCASE_prefix::"This host is within the alpha host group range (HOST0$(range)) (NOTE: Leading zeros and prefix capitalization is insignificant)";}

This policy can be found in/var/cfengine/share/doc/examples/hostrange.cfand downloaded directly fromgithub.

Example Output:

code
R: sys.fqhost = 'host001.example.com'R: sys.uqhost = 'host001'R: hostname -f = 'HOST001.example.com'R: hostname -s = 'HOST001'R: hostname = 'HOST001'R: This host is within the alpha host group range (host1-32)R: This host is within the alpha host group range (host001-32) (NOTE: Leading zeros and prefix capitalization is insignificant)R: This host is within the alpha host group range (HOST01-32) (NOTE: Leading zeros and prefix capitalization is insignificant)

This policy can be found in/var/cfengine/share/doc/examples/hostrange.cfand downloaded directly fromgithub.

Still need help?

Chat Ask a question on Github Mailing list
Version 
master3.24 (LTS)3.21 (LTS)view all versions

[8]ページ先頭

©2009-2025 Movatter.jp