Last active
May 13, 2020 21:06
-
-
Save chuckersjp/5452feb5737f7e9ad69ce6175a1d9533 to your computer and use it in GitHub Desktop.
docker_setup.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Setup Docker for all hosts | |
hosts: all | |
become: true | |
tasks: | |
- name: Install some base packages | |
yum: | |
name: "{{ item }}" | |
state: latest | |
with_items: | |
- wget | |
- git | |
- net-tools | |
- bind-utils | |
- iptables-services | |
- bridge-utils | |
- bash-completion | |
- dnsmasq | |
- lsof | |
- strace | |
- nc | |
- telnet | |
- kexec-tools | |
- sos | |
- psacct | |
- nfs-utils | |
- tmux | |
- name: Install specific docker version | |
yum: | |
name: docker | |
state: docker-1.13.1 | |
- name: Check existence of docker disk | |
stat: | |
path: /dev/sdb | |
register: sdb_disk | |
- name: Stop Docker | |
service: | |
name: docker | |
state: stopped | |
- name: Remove the /dev/sdb1 disk if present | |
parted: | |
device: /dev/sdb | |
number: 1 | |
state: absent | |
when: sdb_disk.stat.exists == True | |
- name: Unmount /var/lib/docker/containers | |
mount: | |
path: /var/lib/docker/containers | |
state: umounted | |
- name: Clear out docker dir | |
file: | |
path: /var/lib/docker/ | |
state: absent | |
- name: Delete docker volume | |
lvol: | |
vg: docker-vg | |
lv: docker-pool | |
state: absent | |
force: yes | |
- name: Delete volume group | |
lvg: | |
vg: docker-vg | |
state: absent | |
force: yes | |
# - name: Configure docker for insecure-registry | |
# lineinfile: | |
# path: /etc/sysconfig/docker | |
# regexp: "^OPTIONS=" | |
# line: "OPTIONS='--insecure-registry=172.30.0.0/16 --selinux-enabled'" | |
- name: Create docker-vg on physical host | |
lvg: | |
vg: docker-vg | |
pvs: /dev/sda2 | |
when: sdb_disk.stat.exists == False | |
- name: Edit docker-storage-setup on physical host | |
copy: | |
dest: /etc/sysconfig/docker-storage-setup | |
content: "VG=docker-vg\n" | |
when: sdb_disk.stat.exists == False | |
- name: Edit docker-storage-setup on vm host | |
copy: | |
dest: /etc/sysconfig/docker-storage-setup | |
content: "DEVS=/dev/sdb\nVG=docker-vg\n" | |
when: sdb_disk.stat.exists == True | |
- name: Clear out /etc/sysconfig/docker-storage | |
copy: | |
dest: /etc/sysconfig/docker-storage | |
content: "" | |
- name: Clean up /dev/sdb if present | |
command: wipefs -a /dev/sdb | |
when: sdb_disk.stat.exists == True | |
- name: Run docker-storage-setup | |
command: "/usr/bin/docker-storage-setup" | |
- name: Start and enable docker | |
service: | |
name: docker | |
state: started | |
enabled: true |
Renamed this to something legible.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an ansible playbook that attempts to wipe out and clean a docker install. It makes certain assumptions about whether a machine is physical or VM based on the absence or presence of a virtual disk used for docker storage.