Skip to content

Commit

Permalink
Fix failure when listing containers (#269)
Browse files Browse the repository at this point in the history
Workaround issue containers/podman#10225
Add retries and pause for "podman ps"
  • Loading branch information
sshnaidm committed Jun 8, 2021
1 parent ed17e7a commit b7e904a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion plugins/modules/podman_container_info.py
Expand Up @@ -315,6 +315,7 @@
"""

import json
import time
from ansible.module_utils.basic import AnsibleModule


Expand All @@ -329,11 +330,21 @@ def get_containers_facts(module, executable, name):
Returns:
list of containers info, stdout, stderr
"""
retry = 0
retry_limit = 4
if not name:
all_names = [executable, 'container', 'ls', '-q', '-a']
rc, out, err = module.run_command(all_names)
# This should not fail in regular circumstances, so retry again
# https://github.com/containers/podman/issues/10225
while rc != 0 and retry <= retry_limit:
module.log(msg="Unable to get list of containers: %s" % err)
time.sleep(1)
retry += 1
rc, out, err = module.run_command(all_names)
if rc != 0:
module.fail_json(msg="Unable to get list of containers: %s" % err)
module.fail_json(msg="Unable to get list of containers during"
" %s retries" % retry_limit)
name = out.split()
if not name:
return [], out, err
Expand Down

0 comments on commit b7e904a

Please sign in to comment.