Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
36bd9efb
Commit
36bd9efb
authored
Aug 14, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop/remove existing docker container if the specified tag is different
Fixes #8278
parent
dc23d71e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
6 deletions
+26
-6
library/cloud/docker
+26
-6
No files found.
library/cloud/docker
View file @
36bd9efb
...
...
@@ -742,6 +742,7 @@ def main():
state
=
module
.
params
.
get
(
'state'
)
count
=
int
(
module
.
params
.
get
(
'count'
))
name
=
module
.
params
.
get
(
'name'
)
image
=
module
.
params
.
get
(
'image'
)
if
count
<
0
:
module
.
fail_json
(
msg
=
"Count must be greater than zero"
)
...
...
@@ -760,12 +761,31 @@ def main():
if
state
in
[
"running"
,
"present"
]:
# make sure a container with `name` exists, if not create and start it
if
name
and
"/"
+
name
not
in
map
(
lambda
x
:
x
.
get
(
'Name'
),
deployed_containers
):
containers
=
manager
.
create_containers
(
1
)
if
state
==
"present"
:
#otherwise it get (re)started later anyways..
manager
.
start_containers
(
containers
)
running_containers
=
manager
.
get_running_containers
()
deployed_containers
=
manager
.
get_deployed_containers
()
if
name
:
# first determine if a container with this name exists
existing_container
=
None
for
deployed_container
in
deployed_containers
:
if
deployed_container
.
get
(
'Name'
)
==
'/
%
s'
%
name
:
existing_container
=
deployed_container
break
# the named container is running, but with a
# different image or tag, so we stop it first
if
existing_container
and
existing_container
.
get
(
'Config'
,
dict
())
.
get
(
'Image'
)
!=
image
:
manager
.
stop_containers
([
existing_container
])
manager
.
remove_containers
([
existing_container
])
running_containers
=
manager
.
get_running_containers
()
deployed_containers
=
manager
.
get_deployed_containers
()
existing_container
=
None
# if the container isn't running (or if we stopped the
# old version above), create and (maybe) start it up now
if
not
existing_container
:
containers
=
manager
.
create_containers
(
1
)
if
state
==
"present"
:
# otherwise it get (re)started later anyways..
manager
.
start_containers
(
containers
)
running_containers
=
manager
.
get_running_containers
()
deployed_containers
=
manager
.
get_deployed_containers
()
if
state
==
"running"
:
# make sure a container with `name` is running
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment