Skip to content

Commit

Permalink
Update main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDoobPG authored and MrDoobPG committed Sep 7, 2019
1 parent b307886 commit d4219b6
Showing 1 changed file with 163 additions and 197 deletions.
360 changes: 163 additions & 197 deletions menu/roles/dockerdeb/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,200 +6,166 @@
# GNU: General Public License v3.0
################################################################################
---
- name: 'Establish Facts'
set_fact:
switch: 'on'
updatecheck: 'default'

- name: 'Docker Check'
stat:
path: '/usr/bin/docker'
register: check

- name: 'Docker Version Check - True'
shell: "docker --version | awk '{print $3}'"
register: updatecheck

- name: 'Switch - On'
set_fact:
switch: 'off'
when: updatecheck.stdout == "18.09.8,"

- name: Install required packages
apt: 'name={{item}} state=present'
with_items:
- apt-transport-https
- ca-certificates
- software-properties-common
when: switch == "on"

- name: Add official gpg signing key
apt_key:
id: 0EBFCD88
url: https://download.docker.com/linux/debian/gpg
when: switch == "on"

- name: 'Stop All Containers'
shell: 'docker stop $(docker ps -a -q)'
ignore_errors: yes
when:
- check.stat.exists == True
- switch == "on"

- name: Add official gpg signing key
apt_key:
id: 0EBFCD88
url: https://download.docker.com/linux/ubuntu/gpg

- name: Add official repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} edge"
filename: docker
register: apt_docker_repositories

- name: Update APT packages list
apt:
update_cache: yes
when: apt_docker_repositories.changed

- name: Release 'docker-ce' from hold
dpkg_selections:
name: docker-ce
selection: install

- name: Install 'docker-ce'
apt:
name: "docker-ce=*18.09.2~3-0~{{ ansible_distribution | lower }}-{{ ansible_distribution_release | lower }}"
state: present
update_cache: yes
force: yes

- name: Put 'docker-ce' into hold
dpkg_selections:
name: docker-ce
selection: hold

- name: Get 'docker-ce' version
shell: "/usr/bin/dockerd-ce --version | head -n 1 | awk '{ print $3 }' | sed 's/,$//'"
register: docker_ce_version
ignore_errors: yes

- name: Display 'docker-ce' version
debug:
msg: "Docker CE version {{ docker_ce_version.stdout }} installed."
when: docker_ce_version is defined

- name: Release 'docker-ce-cli' from hold
dpkg_selections:
name: docker-ce-cli
selection: install

- name: Install 'docker-ce-cli'
apt:
name: "docker-ce-cli=*18.09.2~3-0~{{ ansible_distribution | lower }}-{{ ansible_distribution_release | lower }}"
state: present
update_cache: yes
force: yes

- name: Put 'docker-ce-cli' into hold
dpkg_selections:
name: docker-ce-cli
selection: hold

- name: Get 'docker-ce-cli' version
shell: "/usr/bin/docker --version | head -n 1 | awk '{ print $3 }' | sed 's/,$//'"
register: docker_ce_cli_version
ignore_errors: yes

- name: Display 'docker-ce-cli' version
debug:
msg: "Docker CE CLI version {{ docker_ce_cli_version.stdout }} installed."
when: docker_ce_cli_version is defined

- name: Uninstall 'docker-py' pip module
pip:
name: docker-py
state: absent
ignore_errors: yes

- name: Install 'docker' pip module
pip:
name: docker
state: latest
ignore_errors: yes

- name: Check docker daemon.json exists
stat:
path: /etc/docker/daemon.json
register: docker_daemon

- name: Stop docker to enable overlay2
systemd:
state: stopped
name: docker
enabled: yes
when:
- docker_daemon.stat.exists == False
- switch == "on"

- name: Import daemon.json
copy:
src: daemon.json
dest: /etc/docker/daemon.json
force: yes
mode: 0775
when:
- docker_daemon.stat.exists == False
- switch == "on"

- name: Start docker (Please Wait)
systemd:
state: started
name: docker
enabled: yes
when:
- docker_daemon.stat.exists == False
- switch == "on"

- name: 'Wait for 20 seconds before commencing'
wait_for:
timeout: 20
when: switch == "on"

- name: Check override folder exists
stat:
path: /etc/systemd/system/docker.service.d
register: docker_override

- name: Create override folder
file:
path: /etc/systemd/system/docker.service.d
state: directory
mode: 0775
when:
- docker_override.stat.exists == False
- switch == "on"
tags: docker_standard

- name: Import override file
copy:
src: override.conf
dest: /etc/systemd/system/docker.service.d/override.conf
force: yes
mode: 0775
tags: docker_standard
when: switch == "on"

- name: create plexguide network
docker_network:
name: 'plexguide'
state: present
tags: docker_standard
when: switch == "on"

- name: 'Start All Containers'
shell: 'docker start $(docker ps -a -q)'
ignore_errors: yes
when:
- switch == "on"
- check.stat.exists == True
- hosts: localhost
gather_facts: true
tasks:

- name: "Establish Facts"
set_fact:
switch: "on"
updatecheck: "default"

- name: "Docker Check"
stat:
path: "/usr/bin/docker"
register: check

- name: "Docker Version Check - True"
shell: "docker --version | awk '{print $3}'"
register: updatecheck

- name: "Switch - On"
set_fact:
switch: "off"
when: updatecheck.stdout == "18.09.2,"

- name: Install required packages
apt: "name={{item}} state=present"
with_items:
- apt-transport-https
- ca-certificates
- software-properties-common
when: switch == "on"

- name: Add official gpg signing key
apt_key:
id: 0EBFCD88
url: https://download.docker.com/linux/debian/gpg
when: switch == "on"

- name: "Stop All Containers"
shell: "docker stop $(docker ps -a -q)"
ignore_errors: yes
when:
- check.stat.exists == True
- switch == "on"

- name: Official Repo
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_distribution_release }} edge"
register: apt_docker_repositories
when: switch == "on"

- name: Update APT packages list
apt:
update_cache: yes
when: apt_docker_repositories.changed and switch == "on"

- name: Release docker-ce from hold
dpkg_selections:
name: docker-ce
selection: install
when: switch == "on"

- name: Install docker-ce
apt:
name: docker-ce
state: present
update_cache: yes
when: switch == "on"

- name: Put docker-ce into hold
dpkg_selections:
name: docker-ce
selection: hold
when: switch == "on"

- name: Uninstall docker-py pip module
pip:
name: docker-py
state: absent
ignore_errors: yes
when: switch == "on"

- name: Install docker pip module
pip:
name: docker
state: latest
ignore_errors: yes
when: switch == "on"

- name: Check docker daemon.json exists
stat:
path: /etc/docker/daemon.json
register: docker_daemon

- name: Stop docker to enable overlay2
systemd:
state: stopped
name: docker
enabled: yes
when:
- docker_daemon.stat.exists == False
- switch == "on"

- name: Import daemon.json
copy:
src: /opt/plexguide/menu/roles/dockerdeb/files//daemon.json
dest: /etc/docker/daemon.json
force: yes
mode: 0775
when:
- docker_daemon.stat.exists == False
- switch == "on"

- name: Start docker (Please Wait)
systemd:
state: started
name: docker
enabled: yes
when:
- docker_daemon.stat.exists == False
- switch == "on"

- name: "Wait for 20 seconds before commencing"
wait_for:
timeout: 20
when: switch == "on"

- name: Check override folder exists
stat:
path: /etc/systemd/system/docker.service.d
register: docker_override

- name: Create override folder
file:
path: /etc/systemd/system/docker.service.d
state: directory
mode: 0775
when:
- docker_override.stat.exists == False
- switch == "on"
tags: docker_standard

- name: Import override file
copy:
src: /opt/plexguide/menu/roles/dockerdeb/files//override.conf
dest: /etc/systemd/system/docker.service.d/override.conf
force: yes
mode: 0775
tags: docker_standard
when: switch == "on"

- name: create plexguide network
docker_network:
name: "plexguide"
state: present
tags: docker_standard
when: switch == "on"

- name: "Start All Containers"
shell: "docker start $(docker ps -a -q)"
ignore_errors: yes
when:
- switch == "on"
- check.stat.exists == True

0 comments on commit d4219b6

Please sign in to comment.