ansible-playbook进行磁盘分区挂载

磁盘分区挂载

给server4上/dev/vda分区
ansible-playbook进行磁盘分区挂载_第1张图片

[devops@server4 ansible]$ cat inventory 
[test]
172.25.25.4
  
[root@server1 ansible]# cat my_disk.yml 
---
- hosts: test
  tasks:
    - name: create new primary
      parted: 
        device: /dev/vda
        number: 1 #第一块分区
        part_start: 1MiB
        part_end: 1GiB
        state: present
    - name: create teo partitions
      parted:
        device: /dev/vda
        number: 2 #第二块分区
        part_start: 1GiB
        part_end: 2GiB
        state: present

ansible-playbook my_disk.yml ansible-playbook进行磁盘分区挂载_第2张图片
引入文件进行磁盘分区并挂载

  [root@server1 ansible]# cat my_disk_file.yml 
    ---
    - hosts: localhost
      vars_files:
        - storage_vars.yml
      tasks:
        - name: create new primary
          parted: 
            device: /dev/vda
            number: "{{ item.number }}"
            part_start: "{{ item.start }}"
            part_end: "{{ item.end }}"
            state: present
          loop: "{{ partitions }}"
        - name: create volume group
          lvg:
            vg: myvg
            pvs: /dev/vda1
        - name: Create lv
          lvol:
            vg: myvg
            lv: mylv
            size: 100%VG
            resizefs: true
            force: yes
            state: present
        - name: create xfs filesystem
          filesystem:
            fstype: xfs
            dev: /dev/myvg/mylv
        - name: mount lvs
          mount:
            fstype: xfs #指定文件系统
            src: /dev/myvg/mylv
            path: /var/www/html
            state: mounted

  [root@server1 ansible]# cat storage_vars.yml 
    ---
    partitions:
      - number: 1
        start: 1MiB
        end: 1GiB
      - number: 2
        start: 1GiB
        end: 2GiB

ansible-playbook进行磁盘分区挂载_第3张图片ansible-playbook进行磁盘分区挂载_第4张图片

你可能感兴趣的:(linux企业级)