- name: Create docker data dir
  file: path={{ docker_data_dir }} owner=docker group=docker state=directory mode=0755

- name: Check if systemd exists
  stat: path=/usr/lib/systemd/system/
  register: systemd_check

- name: Docker systemd default config file
  template: src=docker-sysconfig.j2 dest=/etc/sysconfig/docker
  when: systemd_check.stat.exists == true
  
- name: Docker systemd file
  template: src=docker-service.j2 dest=/lib/systemd/system/docker.service backup=yes
  when: systemd_check.stat.exists == true

- name: Install old docker image and container purge cronjob
  cron: name="docker_purge" weekday="6" minute=0 hour=6
        user="docker" job="docker ps -a |grep 'weeks ago'|awk '{print $1}'|xargs --no-run-if-empty docker rm -f; docker images |grep 'weeks ago'|awk '{print $3}'|xargs --no-run-if-empty docker rmi -f"
        cron_file=ansible_docker_purge

- name: Reload systemd
  shell: systemctl daemon-reload

- name: Make sure Docker is started
  service: name=docker.service state=restarted enabled=yes
- name: Create docker data dir
  file: path={{ docker_data_dir }} owner=docker group=docker state=directory mode=0755

- name: Check if systemd exists
  stat: path=/usr/lib/systemd/system/
  register: systemd_check

- name: Docker systemd default config file
  template: src=docker-sysconfig.j2 dest=/etc/sysconfig/docker
  when: systemd_check.stat.exists == true
  
- name: Docker systemd file
  template: src=docker-service.j2 dest=/lib/systemd/system/docker.service backup=yes
  when: systemd_check.stat.exists == true

- name: Install old docker image and container purge cronjob
  cron: name="docker_purge" weekday="6" minute=0 hour=6
        user="docker" job="docker ps -a |grep 'weeks ago'|awk '{print $1}'|xargs --no-run-if-empty docker rm -f; docker images |grep 'weeks ago'|awk '{print $3}'|xargs --no-run-if-empty docker rmi -f"
        cron_file=ansible_docker_purge

- name: Reload systemd
  shell: systemctl daemon-reload

- name: Make sure Docker is started
  service: name=docker.service state=started enabled=yes
Fix for missing systemctl file
Fix for missing systemctl file
