30a83550f626c0ce107b69c87b46b35c55655cb2
[apex-tripleo-heat-templates.git] / extraconfig / pre_deploy / rhel-registration / rhel-registration.yaml
1 heat_template_version: ocata
2
3 description: >
4   RHEL Registration and unregistration software deployments.
5
6 # Note extra parameters can be defined, then passed data via the
7 # environment parameter_defaults, without modifying the parent template
8 parameters:
9   server:
10     type: string
11   # To be defined via a local or global environment in parameter_defaults
12   rhel_reg_activation_key:
13     type: string
14   rhel_reg_auto_attach:
15     type: string
16   rhel_reg_base_url:
17     type: string
18   rhel_reg_environment:
19     type: string
20   rhel_reg_force:
21     type: string
22   rhel_reg_machine_name:
23     type: string
24   rhel_reg_org:
25     type: string
26   rhel_reg_password:
27     type: string
28   rhel_reg_pool_id:
29     type: string
30   rhel_reg_release:
31     type: string
32   rhel_reg_repos:
33     type: string
34   rhel_reg_sat_url:
35     type: string
36   rhel_reg_server_url:
37     type: string
38   rhel_reg_service_level:
39     type: string
40   rhel_reg_user:
41     type: string
42   rhel_reg_type:
43     type: string
44   rhel_reg_method:
45     type: string
46   rhel_reg_sat_repo:
47     type: string
48   rhel_reg_http_proxy_host:
49     type: string
50   rhel_reg_http_proxy_port:
51     type: string
52   rhel_reg_http_proxy_username:
53     type: string
54   rhel_reg_http_proxy_password:
55     type: string
56   UpdateOnRHELRegistration:
57     type: boolean
58     default: false
59     description: |
60       When enabled, the system will perform a yum update after performing the
61       RHEL Registration process.
62
63 resources:
64
65   RHELRegistration:
66     type: OS::Heat::SoftwareConfig
67     properties:
68       group: script
69       inputs:
70         - name: REG_ACTIVATION_KEY
71         - name: REG_AUTO_ATTACH
72         - name: REG_BASE_URL
73         - name: REG_ENVIRONMENT
74         - name: REG_FORCE
75         - name: REG_MACHINE_NAME
76         - name: REG_ORG
77         - name: REG_PASSWORD
78         - name: REG_POOL_ID
79         - name: REG_RELEASE
80         - name: REG_REPOS
81         - name: REG_SAT_URL
82         - name: REG_SERVER_URL
83         - name: REG_SERVICE_LEVEL
84         - name: REG_USER
85         - name: REG_TYPE
86         - name: REG_METHOD
87         - name: REG_SAT_REPO
88         - name: REG_HTTP_PROXY_HOST
89         - name: REG_HTTP_PROXY_PORT
90         - name: REG_HTTP_PROXY_USERNAME
91         - name: REG_HTTP_PROXY_PASSWORD
92       config: {get_file: scripts/rhel-registration}
93
94   RHELRegistrationDeployment:
95     type: OS::Heat::SoftwareDeployment
96     properties:
97       name: RHELRegistrationDeployment
98       server:  {get_param: server}
99       config: {get_resource: RHELRegistration}
100       actions: ['CREATE'] # Only do this on CREATE
101       input_values:
102         REG_ACTIVATION_KEY: {get_param: rhel_reg_activation_key}
103         REG_AUTO_ATTACH: {get_param: rhel_reg_auto_attach}
104         REG_BASE_URL: {get_param: rhel_reg_base_url}
105         REG_ENVIRONMENT: {get_param: rhel_reg_environment}
106         REG_FORCE: {get_param: rhel_reg_force}
107         REG_MACHINE_NAME: {get_param: rhel_reg_machine_name}
108         REG_ORG: {get_param: rhel_reg_org}
109         REG_PASSWORD: {get_param: rhel_reg_password}
110         REG_POOL_ID: {get_param: rhel_reg_pool_id}
111         REG_RELEASE: {get_param: rhel_reg_release}
112         REG_REPOS: {get_param: rhel_reg_repos}
113         REG_SAT_URL: {get_param: rhel_reg_sat_url}
114         REG_SERVER_URL: {get_param: rhel_reg_server_url}
115         REG_SERVICE_LEVEL: {get_param: rhel_reg_service_level}
116         REG_USER: {get_param: rhel_reg_user}
117         REG_TYPE: {get_param: rhel_reg_type}
118         REG_METHOD: {get_param: rhel_reg_method}
119         REG_SAT_REPO: {get_param: rhel_reg_sat_repo}
120         REG_HTTP_PROXY_HOST: {get_param: rhel_reg_http_proxy_host}
121         REG_HTTP_PROXY_PORT: {get_param: rhel_reg_http_proxy_port}
122         REG_HTTP_PROXY_USERNAME: {get_param: rhel_reg_http_proxy_username}
123         REG_HTTP_PROXY_PASSWORD: {get_param: rhel_reg_http_proxy_password}
124
125   RHELUnregistration:
126     type: OS::Heat::SoftwareConfig
127     properties:
128       group: script
129       config: {get_file: scripts/rhel-unregistration}
130       inputs:
131         - name: REG_METHOD
132
133   RHELUnregistrationDeployment:
134     type: OS::Heat::SoftwareDeployment
135     properties:
136       name: RHELUnregistrationDeployment
137       server:  {get_param: server}
138       config: {get_resource: RHELUnregistration}
139       actions: ['DELETE'] # Only do this on DELETE
140       input_values:
141         REG_METHOD: {get_param: rhel_reg_method}
142
143   YumUpdateConfigurationAfterRHELRegistration:
144     type: OS::Heat::SoftwareConfig
145     properties:
146       group: script
147       config: |
148         #!/bin/bash
149         set -x
150         num_updates=$(yum list -q updates | wc -l)
151         if [ "$num_updates" -eq "0" ]; then
152            echo "No packages require updating"
153            exit 0
154         fi
155         full_command="yum -q -y update"
156         echo "Running: $full_command"
157         result=$($full_command)
158         return_code=$?
159         echo "$result"
160         echo "yum return code: $return_code"
161         exit $return_code
162
163   UpdateDeploymentAfterRHELRegistration:
164     type: OS::Heat::SoftwareDeployment
165     depends_on: RHELRegistrationDeployment
166     conditions:
167       update_requested: {get_param: UpdateOnRHELRegistration}
168     properties:
169       name: UpdateDeploymentAfterRHELRegistration
170       config: {get_resource: YumUpdateConfigurationAfterRHELRegistration}
171       server:  {get_param: server}
172       actions: ['CREATE'] # Only do this on CREATE
173
174 outputs:
175   deploy_stdout:
176     description: Deployment reference, used to trigger puppet apply on changes
177     value: {get_attr: [RHELRegistrationDeployment, deploy_stdout]}
178