例子:mountdisk.yml - hosts: all gather_facts: no vars: disks: /dev/vdb1: /data tasks: - name: 'mkdir /data' file: path: '{{ item.value }}' state: directory mode: ..

ansible playbook 挂载硬盘实例

例子:mountdisk.yml

- hosts: all
  gather_facts: no
  vars:
    disks:
      /dev/vdb1: /data
  tasks:
  - name: "mkdir /data"
    file:
      path: "{{ item.value }}"
      state: directory
      mode: 0644
    with_dict: "{{ disks }}"

  - name: umount datanode disks
    mount:
      path: "{{ item.value }}"
      state: absent
    with_dict: "{{ disks }}"

  - name: format datanode disks
    filesystem: fstype=ext4 dev="{{ item.key }}" force=true
    with_dict: "{{ disks }}"

  - name: mount datanode disks
    mount:
      path: "{{ item.value }}"
      src: "{{ item.key }}"
      fstype: ext4
      opts: "defaults"
      state: mounted
    with_dict: "{{ disks }}"

执行

ansible-playbook -i hosts mountdisk.yml
回帖
请输入回帖内容...