Use wait_for_connection instead of wait_for to check container
After creating the container or configuring the bind mounts for the container, we used a task to wait for SSH to respond on the container, using the Ansible wait_for module trying to connect to port 22. When managing containers in Ansible using other connection plugins that use LXC commands on the physical host to execute modules, there may not be an SSH daemon running within the container. In these situations we can accomplish the same check without SSH by using the wait_for_connection module (new in ansible 2.3) to verify that Ansible has a working execution path into the container, but not necessarily via SSH. Change-Id: I1399b6727ec8894dd3b9c464f6addbeea1c1f4f9
This commit is contained in:
parent
f5c72e5076
commit
06269c1884
@ -124,16 +124,12 @@
|
||||
tags:
|
||||
- common-lxc
|
||||
|
||||
- name: Wait for container ssh
|
||||
wait_for:
|
||||
port: "22"
|
||||
delay: "{{ ssh_delay }}"
|
||||
search_regex: "OpenSSH"
|
||||
host: "{{ ansible_host }}"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
register: ssh_wait_check
|
||||
until: ssh_wait_check | success
|
||||
retries: 3
|
||||
- name: Wait for container connectivity
|
||||
wait_for_connection:
|
||||
connect_timeout: "{{ lxc_container_wait_params.connect_timeout | default(omit) }}"
|
||||
delay: "{{ lxc_container_wait_params.delay | default(omit) }}"
|
||||
sleep: "{{ lxc_container_wait_params.sleep | default(omit) }}"
|
||||
timeout: "{{ lxc_container_wait_params.timeout | default(omit) }}"
|
||||
when:
|
||||
- (_mc is defined and _mc | changed) or (_ec is defined and _ec | changed)
|
||||
- not is_metal | bool
|
||||
|
@ -21,3 +21,11 @@ lxc_container_config_list:
|
||||
# Needed by playbooks/common-tasks/os-lxc-container-setup.yml
|
||||
lxc_container_log_path: "/var/log/lxc"
|
||||
|
||||
## Parameters provided to the wait_for_connection module after a container
|
||||
## reboot is triggered by the playbook
|
||||
lxc_container_wait_params:
|
||||
# Wait 3 seconds before attempting the first connection
|
||||
delay: 3
|
||||
# Wait 60 seconds for the container to respond
|
||||
timeout: 60
|
||||
|
||||
|
@ -25,13 +25,12 @@
|
||||
roles:
|
||||
- role: "lxc_container_create"
|
||||
post_tasks:
|
||||
- name: Wait for ssh to be available
|
||||
wait_for:
|
||||
port: "22"
|
||||
host: "{{ ansible_host | default(inventory_hostname) }}"
|
||||
search_regex: OpenSSH
|
||||
delay: 1
|
||||
delegate_to: "{{ physical_host }}"
|
||||
- name: Wait for container connectivity
|
||||
wait_for_connection:
|
||||
connect_timeout: "{{ lxc_container_wait_params.connect_timeout | default(omit) }}"
|
||||
delay: "{{ lxc_container_wait_params.delay | default(omit) }}"
|
||||
sleep: "{{ lxc_container_wait_params.sleep | default(omit) }}"
|
||||
timeout: "{{ lxc_container_wait_params.timeout | default(omit) }}"
|
||||
vars:
|
||||
is_metal: "{{ properties.is_metal|default(false) }}"
|
||||
tags:
|
||||
|
Loading…
Reference in New Issue
Block a user