--- - name: Docker configuration and service management block: - name: Install the Docker default options template: src=docker-default.j2 dest={{ docker_defaults_file }} owner=root group=root mode=0644 when: ansible_service_mgr != 'systemd' notify: Restart docker tags: ['docker', 'docker_conf'] - name: Install the Docker daemon config template: src=daemon.json.j2 dest=/etc/docker/daemon.json owner=root group=root mode=0644 notify: Restart docker tags: ['docker', 'docker_conf'] - name: Create the docker service systemd directory file: dest=/etc/systemd/system/docker.service.d state=directory mode=0755 when: ansible_service_mgr == 'systemd' tags: ['docker', 'docker_systemd', 'docker_conf'] - name: Install the Docker additional systemd unit template: src: docker-systemd-override.conf.j2 dest: /etc/systemd/system/docker.service.d/override.conf owner: root group: root mode: 0644 when: ansible_service_mgr == 'systemd' notify: Restart docker register: reload_systemd tags: ['docker', 'docker_systemd', 'docker_conf'] - name: systemd reload command: systemctl daemon-reload when: reload_systemd is defined and reload_systemd is changed tags: ['docker', 'docker_systemd', 'docker_conf'] - name: Ensure that the service is started and enabled service: name=docker state=started enabled=yes when: docker_install tags: [docker] - name: Cron job that prunes the dangling images block: - name: Install a script that prunes the docker dangling images copy: src: docker-prune-dangling-images.sh dest: /usr/local/sbin/docker-prune-dangling-images owner: root group: root mode: 0744 - name: Install a cron job that prunes the docker images cron: name: Prune docker images cron_file: docker-prune-images special_time: daily user: root state: present job: "/usr/local/sbin/docker-prune-dangling-images" when: docker_prune_dangling_images - name: Disable the cron job that prunes the docker images cron: name: Prune docker images cron_file: docker-prune-images special_time: daily user: root state: absent job: "/usr/local/sbin/docker-prune-dangling-images" when: not docker_prune_dangling_images when: docker_install tags: [docker, docker_prune_images] - block: - name: Remove the docker user user: name=docker state=absent when: not docker_install tags: [docker]