Fix triple molecule modules job

Remove --detach when not starting container.
Change-Id: I9751aa9b6739e8083103791579c1d5a71b938b0b
This commit is contained in:
Sagi Shnaidman 2021-03-02 12:30:08 +02:00
parent 4a6b7c55f9
commit 4eee228dc5
2 changed files with 55 additions and 6 deletions

View File

@ -29,7 +29,7 @@ ARGUMENTS_SPEC_CONTAINER = dict(
name=dict(required=True, type='str'),
executable=dict(default='podman', type='str'),
state=dict(type='str', default='started', choices=[
'absent', 'present', 'stopped', 'started']),
'absent', 'present', 'stopped', 'started', 'created']),
image=dict(type='str'),
annotation=dict(type='dict'),
authfile=dict(type='path'),
@ -1273,6 +1273,8 @@ class PodmanContainer:
self.version,
self.module,
).construct_command_from_params()
if action == 'create':
b_command.remove(b'--detach=True')
full_cmd = " ".join([self.module_params['executable']]
+ [to_native(i) for i in b_command])
self.actions.append(full_cmd)
@ -1317,6 +1319,15 @@ class PodmanContainer:
def recreate(self):
"""Recreate the container."""
if self.running:
self.stop()
self.delete()
self.create()
def recreate_run(self):
"""Recreate and run the container."""
if self.running:
self.stop()
self.delete()
self.run()
@ -1379,9 +1390,20 @@ class PodmanManager:
def make_started(self):
"""Run actions if desired state is 'started'."""
if self.container.exists and self.restart:
if self.container.running:
self.container.restart()
self.results['actions'].append('restarted %s' %
self.container.name)
else:
self.container.start()
self.results['actions'].append('started %s' %
self.container.name)
self.update_container_result()
return
if self.container.running and \
(self.container.different or self.recreate):
self.container.recreate()
self.container.recreate_run()
self.results['actions'].append('recreated %s' %
self.container.name)
self.update_container_result()
@ -1401,7 +1423,7 @@ class PodmanManager:
self.update_container_result()
return
elif self.container.stopped and self.container.different:
self.container.recreate()
self.container.recreate_run()
self.results['actions'].append('recreated %s' %
self.container.name)
self.update_container_result()
@ -1412,6 +1434,26 @@ class PodmanManager:
self.update_container_result()
return
def make_created(self):
"""Run actions if desired state is 'created'."""
if not self.container.exists and not self.image:
self.module.fail_json(msg='Cannot create container when image'
' is not specified!')
if not self.container.exists:
self.container.create()
self.results['actions'].append('created %s' % self.container.name)
self.update_container_result()
return
else:
if (self.container.different or self.recreate):
self.container.recreate()
self.results['actions'].append('recreated %s' %
self.container.name)
self.update_container_result()
return
self.update_container_result(changed=False)
return
def make_stopped(self):
"""Run actions if desired state is 'stopped'."""
if not self.container.exists and not self.image:
@ -1448,7 +1490,8 @@ class PodmanManager:
'present': self.make_started,
'started': self.make_started,
'absent': self.make_absent,
'stopped': self.make_stopped
'stopped': self.make_stopped,
'created': self.make_created,
}
process_action = states_map[self.state]
process_action()

View File

@ -62,6 +62,10 @@ options:
a matching container to be stopped and restarted.
- I(stopped) - Asserts that the container is first I(present), and then
if the container is running moves it to a stopped state.
- I(created) - Asserts that the container exists with given configuration.
If container doesn't exist, the module creates it and leaves it in
'created' state. If configuration doesn't match or 'recreate' option is
set, the container will be recreated
type: str
default: started
choices:
@ -69,6 +73,7 @@ options:
- present
- stopped
- started
- created
image:
description:
- Repository path (or image name) and tag used to create the container.
@ -901,8 +906,9 @@ def main():
)
# work on input vars
if module.params['state'] in ['started', 'present'] and \
not module.params['image']:
if (module.params['state'] in ['started', 'present', 'created']
and not module.params['force_restart']
and not module.params['image']):
module.fail_json(msg="State '%s' required image to be configured!" %
module.params['state'])