/
openshift_raw.py
204 lines (174 loc) · 5.21 KB
/
openshift_raw.py
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
203
204
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2018, Chris Houseknecht <@chouseknecht>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
module: openshift_raw
short_description: Manage OpenShift objects
version_added: "2.5"
author: "Chris Houseknecht (@chouseknecht)"
description:
- Use the OpenShift Python client to perform CRUD operations on OpenShift objects.
- Pass the object definition from a source file or inline. See examples for reading
files and using Jinja templates.
- Access to the full range of K8s and OpenShift APIs.
- Authenticate using either a config file, certificates, password or token.
- Supports check mode.
extends_documentation_fragment:
- k8s_state_options
- k8s_name_options
- k8s_resource_options
- k8s_auth_options
options:
description:
description:
- Use only when creating a project, otherwise ignored. Adds a description to the project
metadata.
display_name:
description:
- Use only when creating a project, otherwise ignored. Adds a display name to the project
metadata.
requirements:
- "python >= 2.7"
- "openshift >= 0.3"
- "PyYAML >= 3.11"
'''
EXAMPLES = '''
- name: Create a project
openshift_raw:
api_version: v1
kind: Project
name: testing
description: Testing
display_name: "This is a test project."
state: present
- name: Create a Persistent Volume Claim from an inline definition
openshift_raw:
state: present
definition:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: elastic-volume
namespace: testing
spec:
resources:
requests:
storage: 5Gi
accessModes:
- ReadWriteOnce
- name: Create a Deployment from an inline definition
openshift_raw:
state: present
definition:
apiVersion: v1
kind: DeploymentConfig
metadata:
name: elastic
labels:
app: galaxy
service: elastic
namespace: testing
spec:
template:
metadata:
labels:
app: galaxy
service: elastic
spec:
containers:
- name: elastic
volumeMounts:
- mountPath: /usr/share/elasticsearch/data
name: elastic-volume
command: ["elasticsearch"]
image: "ansible/galaxy-elasticsearch:2.4.6"
volumes:
- name: elastic-volume
persistentVolumeClaim:
claimName: elastic-volume
replicas: 1
strategy:
type: Rolling
- name: Remove an existing Deployment
openshift_raw:
api_version: v1
kind: DeploymentConfig
name: elastic
namespace: testing
state: absent
- name: Create a Secret
openshift_raw:
definition:
apiVersion: v1
kind: Secret
metadata:
name: mysecret
namespace: testing
type: Opaque
data:
username: "{{ 'admin' | b64encode }}"
password: "{{ 'foobard' | b64encode }}"
- name: Retrieve a Secret
openshift_raw:
api: v1
kind: Secret
name: mysecret
namespace: testing
register: mysecret
# Passing the object definition from a file
- name: Create a Deployment by reading the definition from a local file
openshift_raw:
state: present
src: /testing/deployment.yml
- name: Read definition file from the Ansible controller file system
openshift_raw:
state: present
definition: "{{ lookup('file', '/testing/deployment.yml') | from_yaml }}"
- name: Read definition file from the Ansible controller file system after Jinja templating
openshift_raw:
state: present
definition: "{{ lookup('template', '/testing/deployment.yml') | from_yaml }}"
'''
RETURN = '''
result:
description:
- The created, patched, or otherwise present object. Will be empty in the case of a deletion.
returned: success
type: complex
contains:
api_version:
description: The versioned schema of this representation of an object.
returned: success
type: str
kind:
description: Represents the REST resource this object represents.
returned: success
type: str
metadata:
description: Standard object metadata. Includes name, namespace, annotations, labels, etc.
returned: success
type: complex
spec:
description: Specific attributes of the object. Will vary based on the I(api_version) and I(kind).
returned: success
type: complex
status:
description: Current status details for the object.
returned: success
type: complex
items:
description: Returned only when the I(kind) is a List type resource. Contains a set of objects.
returned: when resource is a List
type: list
'''
from ansible.module_utils.k8s.raw import OpenShiftRawModule
def main():
OpenShiftRawModule().execute_module()
if __name__ == '__main__':
main()