aboutsummaryrefslogtreecommitdiffstats
path: root/extraconfig/pre_deploy/rhel-registration/rhel-registration.yaml
blob: 8b2b230898add651de2af318c65f4f96951f5337 (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
heat_template_version: pike

description: >
  RHEL Registration and unregistration software deployments.

# Note extra parameters can be defined, then passed data via the
# environment parameter_defaults, without modifying the parent template
parameters:
  server:
    type: string
  # To be defined via a local or global environment in parameter_defaults
  rhel_reg_activation_key:
    type: string
  rhel_reg_auto_attach:
    type: string
  rhel_reg_base_url:
    type: string
  rhel_reg_environment:
    type: string
  rhel_reg_force:
    type: string
  rhel_reg_machine_name:
    type: string
  rhel_reg_org:
    type: string
  rhel_reg_password:
    type: string
  rhel_reg_pool_id:
    type: string
  rhel_reg_release:
    type: string
  rhel_reg_repos:
    type: string
  rhel_reg_sat_url:
    type: string
  rhel_reg_server_url:
    type: string
  rhel_reg_service_level:
    type: string
  rhel_reg_user:
    type: string
  rhel_reg_type:
    type: string
  rhel_reg_method:
    type: string
  rhel_reg_sat_repo:
    type: string
  rhel_reg_http_proxy_host:
    type: string
  rhel_reg_http_proxy_port:
    type: string
  rhel_reg_http_proxy_username:
    type: string
  rhel_reg_http_proxy_password:
    type: string
  UpdateOnRHELRegistration:
    type: boolean
    default: false
    description: |
      When enabled, the system will perform a yum update after performing the
      RHEL Registration process.
  deployment_actions:
    default: ['CREATE', 'UPDATE']
    type: comma_delimited_list
    description: >
      List of stack actions that will trigger any deployments in this
      templates. The actions will be an empty list of the server is in the
      toplevel DeploymentServerBlacklist parameter's value.

conditions:
  deployment_actions_empty:
    equals:
      - {get_param: deployment_actions}
      - []
  update_requested:
    equals:
      - {get_param: UpdateOnRHELRegistration}
      - true

resources:

  RHELRegistration:
    type: OS::Heat::SoftwareConfig
    properties:
      group: script
      inputs:
        - name: REG_ACTIVATION_KEY
        - name: REG_AUTO_ATTACH
        - name: REG_BASE_URL
        - name: REG_ENVIRONMENT
        - name: REG_FORCE
        - name: REG_MACHINE_NAME
        - name: REG_ORG
        - name: REG_PASSWORD
        - name: REG_POOL_ID
        - name: REG_RELEASE
        - name: REG_REPOS
        - name: REG_SAT_URL
        - name: REG_SERVER_URL
        - name: REG_SERVICE_LEVEL
        - name: REG_USER
        - name: REG_TYPE
        - name: REG_METHOD
        - name: REG_SAT_REPO
        - name: REG_HTTP_PROXY_HOST
        - name: REG_HTTP_PROXY_PORT
        - name: REG_HTTP_PROXY_USERNAME
        - name: REG_HTTP_PROXY_PASSWORD
      config: {get_file: scripts/rhel-registration}

  RHELRegistrationDeployment:
    type: OS::Heat::SoftwareDeployment
    properties:
      name: RHELRegistrationDeployment
      server:  {get_param: server}
      config: {get_resource: RHELRegistration}
      actions: ['CREATE'] # Only do this on CREATE
      input_values:
        REG_ACTIVATION_KEY: {get_param: rhel_reg_activation_key}
        REG_AUTO_ATTACH: {get_param: rhel_reg_auto_attach}
        REG_BASE_URL: {get_param: rhel_reg_base_url}
        REG_ENVIRONMENT: {get_param: rhel_reg_environment}
        REG_FORCE: {get_param: rhel_reg_force}
        REG_MACHINE_NAME: {get_param: rhel_reg_machine_name}
        REG_ORG: {get_param: rhel_reg_org}
        REG_PASSWORD: {get_param: rhel_reg_password}
        REG_POOL_ID: {get_param: rhel_reg_pool_id}
        REG_RELEASE: {get_param: rhel_reg_release}
        REG_REPOS: {get_param: rhel_reg_repos}
        REG_SAT_URL: {get_param: rhel_reg_sat_url}
        REG_SERVER_URL: {get_param: rhel_reg_server_url}
        REG_SERVICE_LEVEL: {get_param: rhel_reg_service_level}
        REG_USER: {get_param: rhel_reg_user}
        REG_TYPE: {get_param: rhel_reg_type}
        REG_METHOD: {get_param: rhel_reg_method}
        REG_SAT_REPO: {get_param: rhel_reg_sat_repo}
        REG_HTTP_PROXY_HOST: {get_param: rhel_reg_http_proxy_host}
        REG_HTTP_PROXY_PORT: {get_param: rhel_reg_http_proxy_port}
        REG_HTTP_PROXY_USERNAME: {get_param: rhel_reg_http_proxy_username}
        REG_HTTP_PROXY_PASSWORD: {get_param: rhel_reg_http_proxy_password}

  RHELUnregistration:
    type: OS::Heat::SoftwareConfig
    properties:
      group: script
      config: {get_file: scripts/rhel-unregistration}
      inputs:
        - name: REG_METHOD

  RHELUnregistrationDeployment:
    type: OS::Heat::SoftwareDeployment
    properties:
      name: RHELUnregistrationDeployment
      server:  {get_param: server}
      config: {get_resource: RHELUnregistration}
      actions:
        if:
          - deployment_actions_empty
          - []
          - ['DELETE'] # Only do this on DELETE
      input_values:
        REG_METHOD: {get_param: rhel_reg_method}

  YumUpdateConfigurationAfterRHELRegistration:
    type: OS::Heat::SoftwareConfig
    properties:
      group: script
      config: |
        #!/bin/bash
        set -x
        num_updates=$(yum list -q updates | wc -l)
        if [ "$num_updates" -eq "0" ]; then
           echo "No packages require updating"
           exit 0
        fi
        full_command="yum -q -y update"
        echo "Running: $full_command"
        result=$($full_command)
        return_code=$?
        echo "$result"
        echo "yum return code: $return_code"
        exit $return_code

  UpdateDeploymentAfterRHELRegistration:
    type: OS::Heat::SoftwareDeployment
    depends_on: RHELRegistrationDeployment
    condition: update_requested
    properties:
      name: UpdateDeploymentAfterRHELRegistration
      config: {get_resource: YumUpdateConfigurationAfterRHELRegistration}
      server:  {get_param: server}
      actions:
        if:
          - deployment_actions_empty
          - []
          - ['CREATE'] # Only do this on CREATE

outputs:
  deploy_stdout:
    description: Deployment reference, used to trigger puppet apply on changes
    value: {get_attr: [RHELRegistrationDeployment, deploy_stdout]}