【问题标题】:how do i create a zfs filesystem/zpool using ansible using zfs-linux如何使用 zfs-linux 使用 ansible 创建 zfs 文件系统/zpool
【发布时间】:2013-11-25 03:34:07
【问题描述】:

我希望使用 ansible 中的 zfs 模块生成以下等效项,以下使用命令行工作,但由于文件系统已经存在,第二次运行失败。

{{ part_postgres }} 在此实例中设置为 /dev/sdb。

zpool create -O compression=gzip postgres {{ part_postgres }} -O secondarycache=all

目前在 ansible 我有:

- name: Create postgres zpool
    zfs: name=postgres{{ part_postgres }}
         compression=gzip
         state=present
         secondarycache=all
         mountpoint=/postgres
         atime=off

【问题讨论】:

标签: linux ansible zfs


【解决方案1】:

好的 - zfs 模块不会这样做,需要为 zpool 编写一个新模型。也就是说,使用 ansible 中命令模块的“creates”注释来检查 zpool 是否存在很容易:

  - name: Create postgres zpool
    command: zpool create -O compression=gzip postgres /dev/sdb -o ashift=12 -O    secondarycache=all
             creates=/postgres

这将检查 /postgres 是否存在,如果不存在则只运行命令。

【讨论】:

    【解决方案2】:

    这是另一个例子:

    - hosts: all
      vars:
        zfs_pool_name: data
        zfs_pool_mountpoint: /mnt/data
        zfs_pool_mode: mirror
        zfs_pool_devices:
          - sda
          - sdb
        zfs_pool_state: present
        zfs_pool_options:
          - "ashift=12"
      tasks:
        - name: check ZFS pool existance
          command: zpool list -Ho name {{ zfs_pool_name }}
          register: result_pool_list
          ignore_errors: yes
          changed_when: false
    
        - name: create ZFS pool
          command: >-
            zpool create
            {{ '-o' if zfs_pool_options else '' }} {{ zfs_pool_options | join(' -o ') }}
            {{ '-m ' + zfs_pool_mountpoint if zfs_pool_mountpoint else '' }}
            {{ zfs_pool_name }}
            {{ zfs_pool_mode if zfs_pool_mode else '' }}
            {{ zfs_pool_devices | join(' ') }}
          when:
            - zfs_pool_state | default('present') == 'present'
            - result_pool_list.rc == 1
    
        - name: destroy ZFS pool
          command: zpool destroy {{ zfs_pool_name }}
          when:
            - zfs_pool_state | default('present') == 'absent'
            - result_pool_list.rc == 0
    

    【讨论】:

      猜你喜欢
      • 2018-09-30
      • 2022-11-28
      • 1970-01-01
      • 2020-01-07
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 1970-01-01
      相关资源
      最近更新 更多