File: os.cf

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (143 lines) | stat: -rw-r--r-- 5,882 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
bundle common inventory_os
{
vars:

# NOTE TODO: This first part is the old implementation
#            scroll down to the @if minimum_version part for the
#            current implementation.

# This bundle uses variable overwriting, so the definitions further
# down are prioritized.

# Fall back to old LSB based implementation (Lowest priority):

_inventory_lsb_found::
  "description" string => "$(inventory_lsb.os) $(inventory_lsb.release)",
                  meta => { "inventory", "attribute_name=OS" };

!_inventory_lsb_found.windows::
  "description" string => "$(sys.release)",
                  meta => { "inventory", "attribute_name=OS" };

!_inventory_lsb_found.!windows::
  "description" string => "$(sys.flavor) (LSB missing)",
                  meta => { "inventory", "attribute_name=OS" };

# Hard coded values for exceptions / platforms without os-release:

(redhat_5|redhat_6).redhat_pure::
  "description" string => regex_replace("$(inventory_lsb.description)", " release ", " ", "g"),
                    if => isvariable("inventory_lsb.description"),
                  meta => { "inventory", "attribute_name=OS", "derived-from=inventory_lsb.description" };

centos_5::
  "description" string => "CentOS Linux 5", # Matches format of os-release on 7+
                  meta => { "inventory", "attribute_name=OS", "derived-from=centos_5" };

centos_6::
  "description" string => "CentOS Linux 6", # Matches format of os-release on 7+
                  meta => { "inventory", "attribute_name=OS", "derived-from=centos_6" };

# os-release PRETTY_NAME preferred whenever available (Highest priority):

any::
  "description" string => "$(sys.os_release[PRETTY_NAME])",
                    if => isvariable("sys.os_release[PRETTY_NAME]"),
                meta => { "inventory", "attribute_name=OS", "derived-from=sys.os_release" };


# TODO: Remove promises above this line once 3.15+ is what we care about
# New style for Inventory OS variable:
# As short and human-friendly as possible, and consistent across platforms(!)
# Examples: CentOS 7, Ubuntu 18, Debian 9, SUSE 12, etc.
@if minimum_version(3.15)

!_inventory_lsb_found.!windows::
  "description" string => "$(sys.flavor) (LSB missing)",
                  meta => { "inventory", "attribute_name=OS" };

_inventory_lsb_found::
  "description" string => "$(inventory_lsb.os) $(inventory_lsb.release)",
                  meta => { "inventory", "attribute_name=OS" };

windows::
  "description" string => string_replace(string_replace(
                            "$(sys.release)",
                            "Windows Server", "Windows"),
                            "2012 R2", "2012"),
                  meta => { "inventory", "attribute_name=OS" };
# os-release is preferred over LSB:
any::
  # os-release PRETTY_NAME
  "description" string => string_replace(string_replace(string_replace(string_replace(
                            "$(sys.os_release[PRETTY_NAME])",
                            "Red Hat Enterprise Linux Server", "RHEL"),
                            "Debian GNU/Linux", "Debian"),
                            "CentOS Linux", "CentOS"),
                            "Rocky Linux", "Rocky"),
                    if => isvariable("sys.os_release[PRETTY_NAME]"),
                  meta => { "inventory", "attribute_name=OS", "derived-from=sys.os_release" };

  "major_version_from_os_release" string => nth(string_split("$(sys.os_release[VERSION_ID])", "\.", 2), 0),
                                  if => isvariable("sys.os_release[VERSION_ID]");

  # os-release NAME VERSION_ID - preferred when available
  "description" string => string_replace(string_replace(string_replace(string_replace(string_replace(string_replace(
                            "$(sys.os_release[NAME]) $(major_version_from_os_release)",
                            "Red Hat Enterprise Linux Server", "RHEL"), # Seen on RHEL 7...
                            "Red Hat Enterprise Linux", "RHEL"), # On RHEL 8 they changed their mind
                            "Debian GNU/Linux", "Debian"),
                            "CentOS Linux", "CentOS"),
                            "Rocky Linux", "Rocky"),
                            "SLES", "SUSE"),
                    if => and(isvariable("sys.os_release[NAME]"),
                              isvariable("major_version_from_os_release")),
                  meta => { "inventory", "attribute_name=OS", "derived-from=sys.os_release" };

# Hard coded values for exceptions / platforms without os-release:
redhat_5.redhat_pure::
  "description" string => "RHEL 5",
                  meta => { "inventory", "attribute_name=OS", "derived-from=redhat_5" };

redhat_6.redhat_pure::
  "description" string => "RHEL 6",
                  meta => { "inventory", "attribute_name=OS", "derived-from=redhat_6" };

centos_5::
  "description" string => "CentOS 5",
                  meta => { "inventory", "attribute_name=OS", "derived-from=centos_5" };

centos_6::
  "description" string => "CentOS 6",
                  meta => { "inventory", "attribute_name=OS", "derived-from=centos_6" };

@endif

# TODO: Remove all of the logic above once 3.18 clients are expected everywhere
@if minimum_version(3.18)
any::
  "description"
    string => "$(sys.os_name_human) $(sys.os_version_major)",
    meta => { "inventory", "attribute_name=OS" };

rocky::
   "description" -> { "ENT-8292" }
     string => "Rocky $(sys.os_version_major)",
     meta => { "inventory", "attribute_name=OS" };

amzn_2::
   "description" -> { "ENT-10817" }
     string => "Amazon 2",
     meta => { "inventory", "attribute_name=OS" };

any::
  "description"
    string => "$(sys.os_release[PRETTY_NAME])",
    if => and(
      strcmp("$(sys.os_name_human)", "Unknown"),
      isvariable("sys.os_release[PRETTY_NAME]")
    ),
    meta => { "inventory", "attribute_name=OS", "derived-from=sys.os_release" };

@endif
}