playbooks: os-lxc-container-setup: Only stop the container if it's running
Sometimes, despite the container being started by the lxc_container_create role, we may find it stopped when we try to restart it as we see in the following error TASK [Lxc container restart] *************************************************** Thursday 12 October 2017 16:56:03 +0000 (0:00:03.191) 2:11:34.445 ****** FAILED - RETRYING: Lxc container restart (3 retries left). FAILED - RETRYING: Lxc container restart (2 retries left). FAILED - RETRYING: Lxc container restart (1 retries left). fatal: [controller00_horizon_container-a0c1ea76 -> 172.29.236.11]: FAILED! => {"attempts": 3, "changed": true, "cmd": ["lxc-stop", "--name", "controller00_horizon_container-a0c1ea76", "--logfile", "/var/log/lxc/lxc-controller00_horizon_container-a0c1ea76.log", "--logpriority", "INFO", "-t 10"], "delta": "0:00:00.019918", "end": "2017-10-12 16:56:41.885367", "failed": true, "rc": 2, "start": "2017-10-12 16:56:41.865449", "stderr": "controller00_horizon_container-a0c1ea76 is not running", "stderr_lines": ["controller00_horizon_container-a0c1ea76 is not running"], "stdout": "", "stdout_lines": []} It's not exactly clear why the container stopped by itself so lets try to workaround this by simply checking if the container is actually running before we try to stop it. If the container is still in an unusable state, then the lxc-start command that follows this task will fail anyway. Change-Id: I179f9f5dd08c74eaa88666dc19698fcb348703eb
This commit is contained in:
parent
1b232e5108
commit
1938df4ab4
@ -88,6 +88,18 @@
|
||||
tags:
|
||||
- common-lxc
|
||||
|
||||
- name: Check container state
|
||||
command: "lxc-info -n {{ inventory_hostname }} --state"
|
||||
changed_when: false
|
||||
delegate_to: "{{ physical_host }}"
|
||||
register: _lxc_container_state
|
||||
until: _lxc_container_state | success
|
||||
retries: 3
|
||||
delay: 5
|
||||
when:
|
||||
- not is_metal | bool
|
||||
- (_mc is defined and _mc | changed) or (_ec is defined and _ec | changed)
|
||||
|
||||
# Due to https://github.com/ansible/ansible-modules-extras/issues/2691
|
||||
# this uses the LXC CLI tools to ensure that we get logging.
|
||||
# TODO(odyssey4me): revisit this once the bug is fixed and released
|
||||
@ -103,6 +115,7 @@
|
||||
when:
|
||||
- not is_metal | bool
|
||||
- (_mc is defined and _mc | changed) or (_ec is defined and _ec | changed)
|
||||
- _lxc_container_state.stdout.find('RUNNING') != -1
|
||||
tags:
|
||||
- common-lxc
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user