wip
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
---
|
||||
# file: tasks/config.yml
|
||||
|
||||
- name: config - discover NVMe EBS
|
||||
when: aws_ebs_discover | default(True) | bool
|
||||
disks_ebs_config:
|
||||
config: "{{ disks_to_mount }}"
|
||||
become: yes
|
||||
register: __disks_ebs_config
|
||||
|
||||
- set_fact:
|
||||
disks_to_mount: "{{ disks_to_mount|defaut([]) + __disks_ebs_config['ansible_facts']['config'] }}"
|
||||
when: __disks_ebs_config is defined and 'ansible_facts' in __disks_ebs_config
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
# file: tasks/disks.yml
|
||||
|
||||
- name: disks - get disk alignment
|
||||
with_items: '{{ disks_to_mount }}'
|
||||
shell: |
|
||||
if
|
||||
[[ -e /sys/block/{{ item.disk | basename }}/queue/optimal_io_size && -e /sys/block/{{ item.disk | basename }}/alignment_offset && -e /sys/block/{{ item.disk | basename }}/queue/physical_block_size ]];
|
||||
then
|
||||
echo $[$(( ($(cat /sys/block/{{ item.disk | basename }}/queue/optimal_io_size) + $(cat /sys/block/{{ item.disk | basename }}/alignment_offset)) / $(cat /sys/block/{{ item.disk | basename }}/queue/physical_block_size) )) | 2048];
|
||||
else
|
||||
echo 2048;
|
||||
fi
|
||||
args:
|
||||
creates: '{{ item.part | default(item.disk + "1") }}'
|
||||
executable: '/bin/bash'
|
||||
register: disks_offset
|
||||
|
||||
- name: disks - stat if the disk exists
|
||||
with_items: '{{ disks_to_mount }}'
|
||||
stat:
|
||||
path: '{{ item.disk }}'
|
||||
changed_when: False
|
||||
register: disks_stat
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
# file: tasks/filesystems-btrfs.yml
|
||||
|
||||
- name: filesystems-btrfs - create filesystem on the first partition
|
||||
when: item.1.stat.exists
|
||||
with_together:
|
||||
- '{{ disks_to_mount }}'
|
||||
- '{{ disks_stat.results }}'
|
||||
filesystem:
|
||||
dev: '{{ item.0.part | default(item.0.disk + "1") }}'
|
||||
force: '{{ item.0.force|d(omit) }}'
|
||||
fstype: '{{ item.0.fstype }}'
|
||||
opts: '{{ item.0.fsopts|d(omit) }}'
|
||||
become: yes
|
||||
|
||||
- name: filesystems-btrfs - disable periodic fsck and reserved space on ext3 or ext4 formatted disks
|
||||
when: "disks_to_mount and ( item.0.fstype == 'ext4' or item.0.fstype == 'ext3' ) and item.0.disable_periodic_fsck|default(false)|bool and item.1.stat.exists"
|
||||
with_together:
|
||||
- '{{ disks_to_mount }}'
|
||||
- '{{ disks_stat.results }}'
|
||||
environment:
|
||||
PATH: "{{ ansible_env.PATH }}:/usr/sbin:/sbin"
|
||||
shell: tune2fs -c0 -i0 -m0 {{ item.0.part | default(item.0.disk + "1") }}
|
||||
become: yes
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
# file: tasks/filesystems.yml
|
||||
|
||||
- name: filesystems - create filesystem on the first partition
|
||||
when: item.1.stat.exists
|
||||
with_together:
|
||||
- '{{ disks_to_mount }}'
|
||||
- '{{ disks_stat.results }}'
|
||||
filesystem:
|
||||
dev: '{{ item.0.part | default(item.0.disk + "1") }}'
|
||||
force: '{{ item.0.force|d(omit) }}'
|
||||
fstype: '{{ item.0.fstype }}'
|
||||
opts: '{{ item.0.fsopts|d(omit) }}'
|
||||
become: yes
|
||||
|
||||
- name: filesystems - disable periodic fsck and reserved space on ext3 or ext4 formatted disks
|
||||
when: "disks_to_mount and ( item.0.fstype == 'ext4' or item.0.fstype == 'ext3' ) and item.0.disable_periodic_fsck|default(false)|bool and item.1.stat.exists"
|
||||
with_together:
|
||||
- '{{ disks_to_mount }}'
|
||||
- '{{ disks_stat.results }}'
|
||||
environment:
|
||||
PATH: "{{ ansible_env.PATH }}:/usr/sbin:/sbin"
|
||||
shell: tune2fs -c0 -i0 -m0 {{ item.0.part | default(item.0.disk + "1") }}
|
||||
become: yes
|
||||
|
||||
- name: filesystems - btrfs
|
||||
when: "disks_to_mount and ansible_cmdline.fstype == 'btrfs'"
|
||||
import_tasks: filesystems-btrfs.yml
|
||||
tags:
|
||||
- btrfs
|
||||
|
||||
@@ -1,173 +1,29 @@
|
||||
- name: 'Install python-pathlib'
|
||||
pip: >
|
||||
name=pathlib
|
||||
state=present
|
||||
become: yes
|
||||
|
||||
- name: "Discover NVMe EBS"
|
||||
disks_ebs_config:
|
||||
config: "{{ disks_additional_disks }}"
|
||||
register: __disks_ebs_config
|
||||
when: disks_discover_aws_nvme_ebs | default(True) | bool
|
||||
become: yes
|
||||
|
||||
- set_fact:
|
||||
disks_additional_disks: "{{ disks_additional_disks|defaut([]) + __disks_ebs_config['ansible_facts']['config'] }}"
|
||||
when: __disks_ebs_config is defined and 'ansible_facts' in __disks_ebs_config
|
||||
|
||||
- name: "Install parted"
|
||||
package:
|
||||
name: parted
|
||||
state: present
|
||||
use: '{{ disks_package_use }}'
|
||||
when: disks_additional_disks
|
||||
tags: ['disks', 'pkgs']
|
||||
become: yes
|
||||
|
||||
- name: "Install additional fs progs"
|
||||
package:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
with_items: "{{ disks_additional_packages|default([]) }}"
|
||||
when: disks_additional_packages is defined
|
||||
tags: ['disks', 'pkgs']
|
||||
become: yes
|
||||
|
||||
- name: disks - start additional services
|
||||
service:
|
||||
name: "{{item}}"
|
||||
enabled: yes
|
||||
state: started
|
||||
with_items: "{{ disks_additional_services|default([]) }}"
|
||||
tags: ['disks', 'pkgs']
|
||||
become: yes
|
||||
|
||||
- name: "Get disk alignment for disks"
|
||||
shell: |
|
||||
if
|
||||
[[ -e /sys/block/{{ item.disk | basename }}/queue/optimal_io_size && -e /sys/block/{{ item.disk | basename }}/alignment_offset && -e /sys/block/{{ item.disk | basename }}/queue/physical_block_size ]];
|
||||
then
|
||||
echo $[$(( ($(cat /sys/block/{{ item.disk | basename }}/queue/optimal_io_size) + $(cat /sys/block/{{ item.disk | basename }}/alignment_offset)) / $(cat /sys/block/{{ item.disk | basename }}/queue/physical_block_size) )) | 2048];
|
||||
else
|
||||
echo 2048;
|
||||
fi
|
||||
args:
|
||||
creates: '{{ item.part | default(item.disk + "1") }}'
|
||||
executable: '/bin/bash'
|
||||
with_items: '{{ disks_additional_disks }}'
|
||||
register: disks_offset
|
||||
tags: ['disks']
|
||||
|
||||
- name: "Ensure the disk exists"
|
||||
stat:
|
||||
path: '{{ item.disk }}'
|
||||
with_items: '{{ disks_additional_disks }}'
|
||||
register: disks_stat
|
||||
changed_when: False
|
||||
tags: ['disks']
|
||||
|
||||
- name: "Partition additional disks"
|
||||
shell: |
|
||||
if
|
||||
[ -b {{ item.disk }} ]
|
||||
then
|
||||
[ -b {{ item.part | default(item.disk + "1") }} ] || parted -a optimal --script "{{ item.disk }}" mklabel gpt mkpart primary {{ disks_offset.stdout|default("2048") }}s 100% && sleep 5 && partprobe {{ item.disk }}; sleep 5
|
||||
fi
|
||||
args:
|
||||
creates: '{{ item.part | default(item.disk + "1") }}'
|
||||
executable: '/bin/bash'
|
||||
with_items: '{{ disks_additional_disks }}'
|
||||
tags: ['disks']
|
||||
become: yes
|
||||
|
||||
- name: "Create filesystem on the first partition"
|
||||
filesystem:
|
||||
dev: '{{ item.0.part | default(item.0.disk + "1") }}'
|
||||
force: '{{ item.0.force|d(omit) }}'
|
||||
fstype: '{{ item.0.fstype }}'
|
||||
opts: '{{ item.0.fsopts|d(omit) }}'
|
||||
with_together:
|
||||
- '{{ disks_additional_disks }}'
|
||||
- '{{ disks_stat.results }}'
|
||||
when: item.1.stat.exists
|
||||
tags: ['disks']
|
||||
become: yes
|
||||
|
||||
- name: "Disable periodic fsck and reserved space on ext3 or ext4 formatted disks"
|
||||
environment:
|
||||
PATH: "{{ ansible_env.PATH }}:/usr/sbin:/sbin"
|
||||
shell: tune2fs -c0 -i0 -m0 {{ item.0.part | default(item.0.disk + "1") }}
|
||||
with_together:
|
||||
- '{{ disks_additional_disks }}'
|
||||
- '{{ disks_stat.results }}'
|
||||
when: "disks_additional_disks and ( item.0.fstype == 'ext4' or item.0.fstype == 'ext3' ) and item.0.disable_periodic_fsck|default(false)|bool and item.1.stat.exists"
|
||||
tags: ['disks']
|
||||
become: yes
|
||||
|
||||
- name: "Ensure the mount directory exists"
|
||||
file:
|
||||
path: '{{ item.mount }}'
|
||||
state: directory
|
||||
with_items: '{{ disks_additional_disks }}'
|
||||
tags: ['disks']
|
||||
become: yes
|
||||
|
||||
- name: "Get UUID for partition"
|
||||
environment:
|
||||
PATH: "{{ ansible_env.PATH }}:/usr/sbin:/sbin"
|
||||
command: blkid -s UUID -o value {{ item.0.part | default(item.0.disk + "1") }}
|
||||
check_mode: no
|
||||
register: disks_blkid
|
||||
with_together:
|
||||
- '{{ disks_additional_disks }}'
|
||||
- '{{ disks_stat.results }}'
|
||||
changed_when: False
|
||||
when: item.1.stat.exists
|
||||
tags: ['disks']
|
||||
|
||||
- name: "Mount additional disks"
|
||||
mount:
|
||||
name: '{{ item.0.mount }}'
|
||||
fstype: '{{ item.0.fstype }}'
|
||||
opts: '{{ item.0.mount_options|d(omit) }}'
|
||||
passno: '0'
|
||||
src: 'UUID={{ item.1.stdout }}'
|
||||
state: '{{ item.0.mount_state|d("mounted") }}'
|
||||
with_together:
|
||||
- '{{ disks_additional_disks }}'
|
||||
- '{{ disks_blkid.results }}'
|
||||
- '{{ disks_stat.results }}'
|
||||
when: item.2.stat.exists
|
||||
tags: ['disks']
|
||||
register: disks_additional_disks_handler_notify
|
||||
notify:
|
||||
- restart services
|
||||
become: yes
|
||||
|
||||
- name: "Mount additional disks - nfs"
|
||||
mount:
|
||||
name: '{{ item.mount }}'
|
||||
fstype: '{{ item.fstype }}'
|
||||
opts: '{{ item.mount_options|d(omit) }}'
|
||||
src: '{{ item.disk }}'
|
||||
state: '{{ item.mount_state|d("mounted") }}'
|
||||
when: item.fstype == 'nfs'
|
||||
with_items: '{{ disks_additional_disks }}'
|
||||
tags: ['disks']
|
||||
register: disks_additional_disks_nfs_handler_notify
|
||||
notify:
|
||||
- restart services - nfs
|
||||
become: yes
|
||||
|
||||
- name: "Ensure the permissions are set correctly"
|
||||
file:
|
||||
path: '{{ item.mount }}'
|
||||
owner: '{{ item.user | default("root") }}'
|
||||
group: '{{ item.group | default("root") }}'
|
||||
state: directory
|
||||
with_items: '{{ disks_additional_disks }}'
|
||||
when: item.user is defined or item.group is defined
|
||||
tags: ['disks']
|
||||
become: yes
|
||||
---
|
||||
# file: tasks/main.yml
|
||||
|
||||
- import_tasks: vars.yml
|
||||
tags:
|
||||
- vars
|
||||
- import_tasks: config.yml
|
||||
tags:
|
||||
- config
|
||||
- import_tasks: packages.yml
|
||||
tags:
|
||||
- packages
|
||||
- import_tasks: services.yml
|
||||
tags:
|
||||
- services
|
||||
- import_tasks: disks.yml
|
||||
tags:
|
||||
- disks
|
||||
- import_tasks: partitions.yml
|
||||
tags:
|
||||
- partitions
|
||||
- import_tasks: filesystems.yml
|
||||
tags:
|
||||
- filesystems
|
||||
- import_tasks: mount.yml
|
||||
tags:
|
||||
- mount
|
||||
- meta: flush_handlers
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
# file: tasks/mount.yml
|
||||
|
||||
- name: mount - check directory mount exists
|
||||
with_items: '{{ disks_to_mount }}'
|
||||
file:
|
||||
path: '{{ item.mount }}'
|
||||
state: directory
|
||||
become: yes
|
||||
|
||||
- name: mount - mount additional disks
|
||||
when: item.2.stat.exists
|
||||
with_together:
|
||||
- '{{ disks_to_mount }}'
|
||||
- '{{ disks_blkid.results }}'
|
||||
- '{{ disks_stat.results }}'
|
||||
mount:
|
||||
name: '{{ item.0.mount }}'
|
||||
fstype: '{{ item.0.fstype }}'
|
||||
opts: '{{ item.0.mount_options|d(omit) }}'
|
||||
passno: '0'
|
||||
src: 'UUID={{ item.1.stdout }}'
|
||||
state: '{{ item.0.mount_state|d("mounted") }}'
|
||||
become: yes
|
||||
notify:
|
||||
- restart services
|
||||
register: disks_to_mount_handler_notify
|
||||
|
||||
- name: mount - mount additional disks - nfs
|
||||
when: item.fstype == 'nfs'
|
||||
with_items: '{{ disks_to_mount }}'
|
||||
mount:
|
||||
name: '{{ item.mount }}'
|
||||
fstype: '{{ item.fstype }}'
|
||||
opts: '{{ item.mount_options|d(omit) }}'
|
||||
src: '{{ item.disk }}'
|
||||
state: '{{ item.mount_state|d("mounted") }}'
|
||||
become: yes
|
||||
notify:
|
||||
- restart services - nfs
|
||||
register: disks_to_mount_nfs_handler_notify
|
||||
|
||||
- name: mount - set permissions
|
||||
when: item.user is defined or item.group is defined
|
||||
with_items: '{{ disks_to_mount }}'
|
||||
file:
|
||||
path: '{{ item.mount }}'
|
||||
owner: '{{ item.user | default("root") }}'
|
||||
group: '{{ item.group | default("root") }}'
|
||||
state: directory
|
||||
become: yes
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
# file: tasks/packages.yml
|
||||
|
||||
- name: packages - install parted
|
||||
when: disks_to_mount
|
||||
package:
|
||||
name: parted
|
||||
state: present
|
||||
become: yes
|
||||
|
||||
- name: packages - install/remove disks packages
|
||||
when: disks_packages is defined
|
||||
with_items: "{{ disks_packages|default([]) }}"
|
||||
package:
|
||||
name: "{{item.name}}"
|
||||
state: "{{item.state}}"
|
||||
become: yes
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
# file: tasks/partitions.yml
|
||||
|
||||
- name: partitions - extend additional disks partitions
|
||||
with_items: '{{ disks_to_mount }}'
|
||||
shell: |
|
||||
if
|
||||
[ -b {{ item.disk }} ]
|
||||
then
|
||||
[ -b {{ item.part | default(item.disk + "1") }} ] || parted -a optimal --script "{{ item.disk }}" mklabel gpt mkpart primary {{ disks_offset.stdout|default("2048") }}s 100% && sleep 5 && partprobe {{ item.disk }}; sleep 5
|
||||
fi
|
||||
args:
|
||||
creates: '{{ item.part | default(item.disk + "1") }}'
|
||||
executable: '/bin/bash'
|
||||
become: yes
|
||||
|
||||
- name: partitions - get UUID
|
||||
when: item.1.stat.exists
|
||||
with_together:
|
||||
- '{{ disks_to_mount }}'
|
||||
- '{{ disks_stat.results }}'
|
||||
environment:
|
||||
PATH: "{{ ansible_env.PATH }}:/usr/sbin:/sbin"
|
||||
command: blkid -s UUID -o value {{ item.0.part | default(item.0.disk + "1") }}
|
||||
changed_when: False
|
||||
check_mode: no
|
||||
become: yes
|
||||
register: disks_blkid
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
# file: tasks/services.yml
|
||||
|
||||
- name: services - enable/disable disks services
|
||||
when: ansible_service_mgr|lower != "openrc"
|
||||
with_items: "{{ disks_services|default([]) }}"
|
||||
service:
|
||||
name: "{{item.name}}"
|
||||
state: "{{item.state}}"
|
||||
enabled: "{{item.enabled}}"
|
||||
become: yes
|
||||
|
||||
- name: services - openrc - enable/disable disks services
|
||||
when: ansible_service_mgr|lower == "openrc"
|
||||
with_items: "{{ disks_services|default([]) }}"
|
||||
service:
|
||||
name: "{{item.name}}"
|
||||
state: "{{item.state}}"
|
||||
enabled: "{{item.enabled}}"
|
||||
runlevel: boot
|
||||
become: yes
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
---
|
||||
# file: tasks/vars.yml
|
||||
|
||||
- name: vars - load per operating system variables
|
||||
include_vars: "{{item}}"
|
||||
with_first_found:
|
||||
- paths:
|
||||
- "vars/"
|
||||
- files:
|
||||
- "{{ansible_distribution|lower}}-{{ansible_distribution_version|lower}}-{{ansible_machine}}.yml" # centos-6.4-i386.yml ubuntu-16.04-x86_64.yml
|
||||
- "{{ansible_distribution|lower}}-{{ansible_distribution_version|lower}}.yml" # centos-6.4.yml ubuntu-16.04.yml
|
||||
- "{{ansible_distribution|lower}}-{{ansible_distribution_major_version|lower}}-{{ansible_machine}}.yml" # centos-6-i386.yml ubuntu-16-x86_64.yml
|
||||
- "{{ansible_distribution|lower}}-{{ansible_distribution_major_version|lower}}.yml" # centos-6.yml ubuntu-16.yml
|
||||
- "{{ansible_os_family|lower}}-{{ansible_distribution_version|lower}}-{{ansible_machine}}.yml" # redhat-6.4-i386.yml debian-8.5-x86_64.yml
|
||||
- "{{ansible_os_family|lower}}-{{ansible_distribution_version|lower}}.yml" # redhat-6.4.yml debian-8.5.yml
|
||||
- "{{ansible_os_family|lower}}-{{ansible_distribution_major_version|lower}}-{{ansible_machine}}.yml" # redhat-6-i386.yml debian-8-x86_64.yml
|
||||
- "{{ansible_os_family|lower}}-{{ansible_distribution_major_version|lower}}.yml" # redhat-6.yml debian-8.yml
|
||||
- "{{ansible_distribution|lower}}-{{ansible_machine}}.yml" # centos-i386.yml ubuntu-x86_64.yml
|
||||
- "{{ansible_distribution|lower}}.yml" # centos.yml ubuntu.yml
|
||||
- "{{ansible_os_family|lower}}-{{ansible_machine}}.yml" # redhat-i386.yml debian-x86_64.yml
|
||||
- "{{ansible_os_family|lower}}.yml" # redhat.yml debian.yml
|
||||
- "{{ansible_system|lower}}-{{ansible_machine}}.yml" # linux-i386.yml linux-x86_64.yml
|
||||
- "{{ansible_system|lower}}.yml" # linux.yml
|
||||
- "default.yml" # default.yml
|
||||
skip: true
|
||||
|
||||
- name: vars - override with local variables
|
||||
include_vars: "{{item}}"
|
||||
with_first_found:
|
||||
- paths:
|
||||
- "vars/"
|
||||
- files:
|
||||
- "local.yml"
|
||||
skip: true
|
||||
|
||||
Reference in New Issue
Block a user