Question

I want the equivalent of the following to be generated using the zfs module in ansible, the following works using the command line, but fails on second run as the filesystem already exists.

{{ part_postgres }} is set to /dev/sdb in this instance.

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

Currently in ansible I have:

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

La solution

Ok - the zfs module won't do it, would need to write a new model for zpool. That said, its easy enough to check for zpool existing using the 'creates' annotation for the command module in ansible:

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

This will check if /postgres exists, and only run the command if it doesn't.

Autres conseils

Here is another example:

- 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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top