-
Notifications
You must be signed in to change notification settings - Fork 1
/
CentOS7x_Prepare-LVM-for-Docker-playbook.yml
107 lines (81 loc) · 3.99 KB
/
CentOS7x_Prepare-LVM-for-Docker-playbook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
################################################################################
# description: Prepares CentOS7x for Docker by setting up LVM using Docker's published best practices
# usage: ansible-playbook CentOS7x_Prepare-LVM-for-Docker-playbook.yml
# example: ansible-playbook CentOS7x_Prepare-LVM-for-Docker-playbook.yml --extra-vars 'HostOrGroup=Swarm1 BlkDev=/dev/sdb'
# author: Ernest G. Wilson II <[email protected]> (https://github.com/ernestgwilsonii)
# license: MIT
################################################################################
# Ansible Playbook options
# REF: http://docs.ansible.com/ansible/playbooks.html
#####################################################
- name: Prepare thinpool LVM on specified block device(s) for Docker
hosts: "{{ HostOrGroup|default ('FATAL ERROR --> HostOrGroup NOT SET! You must specify either a Host or a Group name!') }}"
serial: "100%"
gather_facts: False
tasks:
# Install yum packages
# REF: http://docs.ansible.com/ansible/yum_module.html
######################################################
- name: Install lvm2.x86_64
yum:
name: lvm2.x86_64
state: latest
# command - Executes a command on a remote node
# REF: http://docs.ansible.com/ansible/command_module.html
##########################################################
# Create LVM physical volume on {{BlkDev|default ('/dev/sdb')}}
- name: "pvcreate {{BlkDev|default ('/dev/sdb')}}"
command: "/usr/sbin/pvcreate {{BlkDev|default ('/dev/sdb')}}"
# Create LVM volume group vg_docker
- name: "vgcreate vg_docker {{BlkDev|default ('/dev/sdb')}}"
command: "/usr/sbin/vgcreate vg_docker {{BlkDev|default ('/dev/sdb')}}"
# lvol - Configure LVM logical volumes
# REF: http://docs.ansible.com/ansible/lvol_module.html
#######################################################
# lvcreate --thinpool vg_docker/lv_docker_thinpool -n lv_docker_thinpool vg_docker -l 85%VG
- name: Create thin logical volume vg_docker/lv_docker_thinpool on /dev/sdb
lvol:
vg: vg_docker
lv: lv_docker_thinpool
pvs: "{{BlkDev|default ('/dev/sdb')}}"
size: 85%PVS
opts: --thinpool vg_docker/lv_docker_thinpool
# file - Sets attributes of files and directories
# http://docs.ansible.com/ansible/file_module.html
##################################################
- name: Create directory /etc/docker if it does not already exist
file:
path: /etc/docker
owner: root
group: root
mode: 0755
state: directory
# Use the copy module to copy various files into place
# REF: http://docs.ansible.com/ansible/copy_module.html
#######################################################
# /etc/lvm/profile/vg_docker-lv_docker_thinpool.profile
- name: Copy LVM configuration file vg_docker-lv_docker_thinpool.profile from Ansible files/Docker/vg_docker-lv_docker_thinpool.profile to Docker remote /etc/lvm/profile/vg_docker-lv_docker_thinpool.profile
copy:
src=files/Docker/vg_docker-lv_docker_thinpool.profile
dest=/etc/lvm/profile/vg_docker-lv_docker_thinpool.profile
owner=root
group=root
mode=0444
# command - Executes a command on a remote node
# REF: http://docs.ansible.com/ansible/command_module.html
##########################################################
# Apply the desired autoextend LVM policy to the Docker thinpool
- name: "lvchange --metadataprofile vg_docker-lv_docker_thinpool vg_docker/lv_docker_thinpool"
command: "/usr/sbin/lvchange --metadataprofile vg_docker-lv_docker_thinpool vg_docker/lv_docker_thinpool"
# Use the copy module to copy various files into place
# REF: http://docs.ansible.com/ansible/copy_module.html
#######################################################
# /etc/docker/daemon.json
- name: Copy Docker configuration file daemon.json from Ansible files/Docker/etc_docker_daemon.json to Docker remote /etc/docker/daemon.json
copy:
src=files/Docker/etc_docker_daemon.json
dest=/etc/docker/daemon.json
owner=root
group=root
mode=0444