fabrica/packer/provisioning/playbooks/prepare_data_disk.yml

108 lines
2.6 KiB
YAML

---
- name: Prepare data disk
hosts: all
environment:
http_proxy: "{{ lookup('env','http_proxy') }}"
https_proxy: "{{ lookup('env','https_proxy') }}"
HTTPS_PROXY: "{{ lookup('env','HTTPS_PROXY') }}"
HTTP_PROXY: "{{ lookup('env','HTTP_PROXY') }}"
vars:
fsconf:
vgn: "{{ lookup('env', 'vgname') }}"
lvs: "{{ lookup('env', 'lvnames').split(' ') }}"
szs: "{{ lookup('env', 'lvsizes').split(' ') }}"
fss: "{{ lookup('env', 'lvfssys').split(' ') }}"
mps: "{{ lookup('env', 'lvmntps').split(' ') }}"
tasks:
- name: Create the "datavg" Volume group.
lvg:
pvs: "/dev/vdb"
vg: "{{ fsconf.vgn }}"
pesize: "16"
pv_options: '-Z y'
force: no
state: present
- name: Create logical volumes.
lvol:
vg: "datavg"
lv: "{{ item }}"
size: "{{ fsconf.szs[idx] }}"
active: yes
force: no
state: present
loop: "{{ fsconf.lvs }}"
loop_control:
index_var: idx
- name: Create filesystems
filesystem:
fstype: "{{ fsconf.fss[idx] }}"
dev: "/dev/datavg/{{ item }}"
loop: "{{ fsconf.lvs }}"
loop_control:
index_var: idx
- name: Find what to backup
stat:
path: "{{ item }}"
with_items: "{{ fsconf.mps }}"
register: mountPoints
- name: Create mount points
file:
path: "{{ fsconf.mps[idx] }}"
state: directory
mode: '0755'
loop: "{{ fsconf.lvs }}"
loop_control:
index_var: idx
- name: Create temporary mount points
file:
path: "/tmp{{ fsconf.mps[idx] }}"
state: directory
mode: '0755'
loop: "{{ fsconf.lvs }}"
loop_control:
index_var: idx
- name: Mount fs in temporary mount points
command: mount /dev/datavg/"{{ item }}" "/tmp{{ fsconf.mps[idx] }}"
loop: "{{ fsconf.lvs }}"
loop_control:
index_var: idx
- name: Configure filesystems create entry in fstab
mount:
path: "{{ fsconf.mps[idx] }}"
src: /dev/datavg/{{ item }}
state: present
fstype: "{{ fsconf.fss[idx] }}"
loop: "{{ fsconf.lvs }}"
loop_control:
index_var: idx
- name: Fill new mount points if exists
become: true
delegate_to: "{{ inventory_hostname }}"
synchronize:
mode: push
src: "{{ item.item }}/"
dest: "/tmp{{ item.item }}/"
times: yes
perms: yes
owner: yes
group: yes
links: yes
recursive: yes
with_items: "{{ mountPoints.results }}"
when: item.stat.exists