Browse Source

Stop using handlers

With the switch to tripleo_free in stable/train, we can no longer
reliably use handlers.  That being said, handlers don't make sense when
you are forcing them to run with a flush handlers anyway. So this change
takes the code we used in the handler and makes them explicit tasks in
the required locations where we used to do a flush handlers.  This
change should also improve the scope of some tasks to only occur when
necessary.

Change-Id: I1e31af24a4c1b9356a5971c6c1cb717d39d1e9b2
Closes-Bug: #1909750
changes/48/770148/10
Alex Schultz 3 months ago
parent
commit
dc3a577652
3 changed files with 74 additions and 25 deletions
  1. +26
    -8
      tasks/docker-distribution.yml
  2. +47
    -17
      tasks/docker.yml
  3. +1
    -0
      tasks/install-engine.yml

+ 26
- 8
tasks/docker-distribution.yml View File

@ -7,6 +7,7 @@
name: docker-distribution
state: present
become: true
register: _distro_install
- name: manage /etc/docker-distribution/registry/config.yml
template:
@ -14,14 +15,31 @@
dest: /etc/docker-distribution/registry/config.yml
mode: '0644'
become: true
register: _distro_config
notify: restart docker-distribution service
- name: force systemd to reread configs
meta: flush_handlers
- name: enable and start docker-distribution
systemd:
enabled: true
state: started
name: docker-distribution
- name: Handle docker-distribution restart
become: true
when: _distro_install is changed or _distro_config is changed
block:
- name: Reload systemd
systemd:
daemon_reload: yes
become: true
- name: Reload docker-distribution
service:
enabled: true
name: docker-distribution
state: restarted
become: true
# NOTE(bogdando): import caveats https://github.com/ansible/ansible/issues/42621
- name: Wait for registry
uri:
# Just checking API version should be fine
# https://docs.docker.com/registry/spec/api/#api-version-check
url: "http://{{ container_registry_host }}:{{ container_registry_port }}/v2/"
return_content: yes
register: registry_status
retries: 10
delay: 5
until: "registry_status.status|int == 200 and 'OK' in registry_status.msg"

+ 47
- 17
tasks/docker.yml View File

@ -69,7 +69,7 @@
value: ""
create: yes
mode: '0644'
notify: restart docker service
register: _cfg_flags
when: ansible_service_mgr == 'systemd'
- name: configure OPTIONS in /etc/sysconfig/docker
@ -79,7 +79,7 @@
line: "OPTIONS='{{ _full_docker_options }}'"
create: yes
mode: '0644'
notify: restart docker service
register: _cfg_options
- name: configure INSECURE_REGISTRY in /etc/sysconfig/docker
lineinfile:
@ -88,7 +88,7 @@
line: "INSECURE_REGISTRY='{{ registry_flags }}'"
mode: '0644'
when: container_registry_insecure_registries | length > 0
notify: restart docker service
register: _cfg_insecure
vars:
registry_flags: --insecure-registry {{ container_registry_insecure_registries | join(' --insecure-registry ') }}
@ -97,7 +97,7 @@
path: "{{ item | dirname }}"
state: directory
mode: '0755'
notify: restart docker service
register: _cfg_sockets
with_items: "{{ container_registry_additional_sockets }}"
when: container_registry_additional_sockets | length > 0
@ -106,7 +106,7 @@
src: docker-daemon.json.j2
dest: /etc/docker/daemon.json
mode: '0644'
notify: restart docker service
register: _cfg_daemon
- name: configure DOCKER_STORAGE_OPTIONS in /etc/sysconfig/docker-storage
lineinfile:
@ -116,7 +116,7 @@
create: yes
mode: '0644'
when: container_registry_storage_options | length > 0
notify: restart docker service
register: _cfg_storage
- name: configure DOCKER_NETWORK_OPTIONS in /etc/sysconfig/docker-network
lineinfile:
@ -126,33 +126,63 @@
create: yes
mode: '0644'
when: container_registry_network_options | length > 0
notify: restart docker service
register: _cfg_network
- name: ensure docker group exists
group:
name: docker
state: present
register: _cfg_group
- name: add deployment user to docker group
user:
name: "{{ container_registry_deployment_user }}"
groups: docker
append: yes
register: _cfg_user
when: container_registry_deployment_user | length > 0
- name: reset ssh connection to pick up docker group
meta: reset_connection
when: container_registry_deployment_user | length > 0
- name: force systemd to reread configs
meta: flush_handlers
when: _cfg_group is changed or _cfg_user is changed
- name: enable and start docker
systemd:
enabled: true
state: started
name: docker
when: ansible_service_mgr == 'systemd'
- name: Handle docker restart
when:
- (_cfg_flags is changed
or _cfg_options is changed
or _cfg_insecure is changed
or _cfg_sockets is changed
or _cfg_daemon is changed
or _cfg_storage is changed
or _cfg_network is changed
or _cfg_group is changed
or _cfg_user is changed)
block:
- name: Reload systemd
systemd:
daemon_reload: yes
become: true
when:
- ansible_service_mgr == 'systemd'
- _cfg_flags is changed
- name: Reload docker
service:
name: docker
enabled: true
state: restarted
become: true
- name: Pause while Docker restarts
shell: sleep 10
changed_when: false
- name: Wait for docker
command: /usr/bin/docker images
register: docker_ready
retries: 10
delay: 5
until: docker_ready.rc == 0
- name: mark docker configured
lineinfile:


+ 1
- 0
tasks/install-engine.yml View File

@ -26,4 +26,5 @@
- name: Start Docker daemon
service:
name: docker
enabled: true
state: started

Loading…
Cancel
Save