ansible playbook-格式化新的卷并创建LVM卷


playbook如下:

---

- hosts: server1
  user: ubuntu
  sudo: yes
  gather_facts: no
  vars:
    mntp:  "/data01"
    vgname: "vg01"
    pvname1: "/dev/xvdf1"
    pvname: "/dev/xvdf"
    lv1: "data01"

  tasks:
  - name: update apt repo
    apt: update_cache=yes
  - name: install  lvm2
    apt: name=lvm2 state=present

  - script: ./scripts/disks.sh   "{{ pvname }}"      #a script to create LVM partion and create physical volume

  - name: filesystem | Create pv,vg,lv and file systems
    lvg:  vg={{ vgname }}  pvs={{ pvname1 }}

  - name: filesystem | create lv
    lvol: vg={{ vgname }}  lv={{ lv1 }}  size=100%FREE

  - name: filesystem | create fs
    filesystem: fstype=ext4 dev=/dev/{{ vgname }}/{{ lv1 }}

  - name: Creates directory
    file: path=${mntp} state=directory

  - name: filesytem | mount dir

    mount: name={{mntp}} src=/dev/{{vgname}}/{{lv1}} dump=1 passno=2 fstype=ext4 state=mounted



其中scripts/disks.sh如下:

#!/bin/sh
sdd=$1
for i in $sdd
do
echo "n
p
1


t
8e
w
"|fdisk $i;pvcreate "$i"1;done

你可能感兴趣的:(ansible)