Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kubespray
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
Kubespray
Commits
f4476f25
Unverified
Commit
f4476f25
authored
7 years ago
by
Chad Swenson
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #2435 from chadswen/kube-module-enhancements
kube Module Enhancements
parents
569613f2
8960d5bc
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
library/kube.py
+35
-19
35 additions, 19 deletions
library/kube.py
with
35 additions
and
19 deletions
library/kube.py
+
35
−
19
View file @
f4476f25
...
...
@@ -18,7 +18,9 @@ options:
required: false
default: null
description:
- The path and filename of the resource(s) definition file.
- The path and filename of the resource(s) definition file(s).
- To operate on several files this can accept a comma separated list of files or a list of files.
aliases: [
'
files
'
,
'
file
'
,
'
filenames
'
]
kubectl:
required: false
default: null
...
...
@@ -86,6 +88,15 @@ EXAMPLES = """
- name: test nginx is present
kube: filename=/tmp/nginx.yml
- name: test nginx and postgresql are present
kube: files=/tmp/nginx.yml,/tmp/postgresql.yml
- name: test nginx and postgresql are present
kube:
files:
- /tmp/nginx.yml
- /tmp/postgresql.yml
"""
...
...
@@ -112,7 +123,7 @@ class KubeManager(object):
self
.
all
=
module
.
params
.
get
(
'
all
'
)
self
.
force
=
module
.
params
.
get
(
'
force
'
)
self
.
name
=
module
.
params
.
get
(
'
name
'
)
self
.
filename
=
module
.
params
.
get
(
'
filename
'
)
self
.
filename
=
[
f
.
strip
()
for
f
in
module
.
params
.
get
(
'
filename
'
)
or
[]]
self
.
resource
=
module
.
params
.
get
(
'
resource
'
)
self
.
label
=
module
.
params
.
get
(
'
label
'
)
...
...
@@ -122,7 +133,7 @@ class KubeManager(object):
rc
,
out
,
err
=
self
.
module
.
run_command
(
args
)
if
rc
!=
0
:
self
.
module
.
fail_json
(
msg
=
'
error running kubectl (%s) command (rc=%d)
: %s
'
%
(
'
'
.
join
(
args
),
rc
,
out
or
err
))
msg
=
'
error running kubectl (%s) command (rc=%d)
, out=
\'
%s
\'
, err=
\'
%s
\'
'
%
(
'
'
.
join
(
args
),
rc
,
out
,
err
))
except
Exception
as
exc
:
self
.
module
.
fail_json
(
msg
=
'
error running kubectl (%s) command: %s
'
%
(
'
'
.
join
(
args
),
str
(
exc
)))
...
...
@@ -147,7 +158,7 @@ class KubeManager(object):
if
not
self
.
filename
:
self
.
module
.
fail_json
(
msg
=
'
filename required to create
'
)
cmd
.
append
(
'
--filename=
'
+
self
.
filename
)
cmd
.
append
(
'
--filename=
'
+
'
,
'
.
join
(
self
.
filename
)
)
return
self
.
_execute
(
cmd
)
...
...
@@ -161,7 +172,7 @@ class KubeManager(object):
if
not
self
.
filename
:
self
.
module
.
fail_json
(
msg
=
'
filename required to reload
'
)
cmd
.
append
(
'
--filename=
'
+
self
.
filename
)
cmd
.
append
(
'
--filename=
'
+
'
,
'
.
join
(
self
.
filename
)
)
return
self
.
_execute
(
cmd
)
...
...
@@ -173,7 +184,7 @@ class KubeManager(object):
cmd
=
[
'
delete
'
]
if
self
.
filename
:
cmd
.
append
(
'
--filename=
'
+
self
.
filename
)
cmd
.
append
(
'
--filename=
'
+
'
,
'
.
join
(
self
.
filename
)
)
else
:
if
not
self
.
resource
:
self
.
module
.
fail_json
(
msg
=
'
resource required to delete without filename
'
)
...
...
@@ -197,27 +208,31 @@ class KubeManager(object):
def
exists
(
self
):
cmd
=
[
'
get
'
]
if
not
self
.
resource
:
return
False
if
self
.
filename
:
cmd
.
append
(
'
--filename=
'
+
'
,
'
.
join
(
self
.
filename
))
else
:
if
not
self
.
resource
:
self
.
module
.
fail_json
(
msg
=
'
resource required without filename
'
)
cmd
.
append
(
self
.
resource
)
cmd
.
append
(
self
.
resource
)
if
self
.
name
:
cmd
.
append
(
self
.
name
)
if
self
.
name
:
cmd
.
append
(
self
.
name
)
cmd
.
append
(
'
--no-headers
'
)
if
self
.
label
:
cmd
.
append
(
'
--selector=
'
+
self
.
label
)
if
self
.
l
abe
l
:
cmd
.
append
(
'
--
selector=
'
+
self
.
label
)
if
self
.
a
ll
:
cmd
.
append
(
'
--
all-namespaces
'
)
if
self
.
all
:
cmd
.
append
(
'
--all-namespaces
'
)
cmd
.
append
(
'
--no-headers
'
)
result
=
self
.
_execute_nofail
(
cmd
)
if
not
result
:
return
False
return
True
# TODO: This is currently unused, perhaps convert to 'scale' with a replicas param?
def
stop
(
self
):
if
not
self
.
force
and
not
self
.
exists
():
...
...
@@ -226,7 +241,7 @@ class KubeManager(object):
cmd
=
[
'
stop
'
]
if
self
.
filename
:
cmd
.
append
(
'
--filename=
'
+
self
.
filename
)
cmd
.
append
(
'
--filename=
'
+
'
,
'
.
join
(
self
.
filename
)
)
else
:
if
not
self
.
resource
:
self
.
module
.
fail_json
(
msg
=
'
resource required to stop without filename
'
)
...
...
@@ -253,7 +268,7 @@ def main():
module
=
AnsibleModule
(
argument_spec
=
dict
(
name
=
dict
(),
filename
=
dict
(),
filename
=
dict
(
type
=
'
list
'
,
aliases
=
[
'
files
'
,
'
file
'
,
'
filenames
'
]
),
namespace
=
dict
(),
resource
=
dict
(),
label
=
dict
(),
...
...
@@ -263,7 +278,8 @@ def main():
all
=
dict
(
default
=
False
,
type
=
'
bool
'
),
log_level
=
dict
(
default
=
0
,
type
=
'
int
'
),
state
=
dict
(
default
=
'
present
'
,
choices
=
[
'
present
'
,
'
absent
'
,
'
latest
'
,
'
reloaded
'
,
'
stopped
'
]),
)
),
mutually_exclusive
=
[[
'
filename
'
,
'
list
'
]]
)
changed
=
False
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment