ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
827 stars 1.52k forks source link

lvol: Error: "Command does not accept argument /dev/sdb1" when doing lvreduce #3320

Open markfaine opened 3 years ago

markfaine commented 3 years ago

Summary

I have a task that is used to manage a logical volume. It's a one size fits all task that is intended to be used for creating, reducing, extending, etc. a logical volume, however, it fails with the error message: "Command does not accept argument "

This works fine when I create or extend the logical volume.

I suspect because it's being included in the command here as a parameter and the lvreduce command doesn't know what to do with it.

So I tested removing that variable from the format string and it works fine without it. Is this a bug or is there something else going on that I don't understand that necessitates the variable being present?

I was also able to work around it by omitting the pvs value when shrink is true:

  pvs: "{{ item.pvs | join(',') if item.shrink is defined and item.shrink else omit }}"

Though, in some cases, this will result in an empty string for pvs, even when it should not be since more than one operation in the role may use that same variable.

Issue Type

Bug Report

Component Name

lvol

Ansible Version

$ ansible --version
ansible 2.10.10
  config file = /home/mfaine/development/collections/ansible_collections/nics/utility/ansible.cfg
  configured module search path = ['/home/mfaine/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mfaine/development/collections/ansible_collections/nics/utility/virtualenv/lib/python3.8/site-packages/ansible
  executable location = /home/mfaine/development/collections/ansible_collections/nics/utility/virtualenv/bin/ansible
  python version = 3.8.3 (default, Sep 22 2020, 14:37:11) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

Configuration

$ ansible-config dump --only-changed

ANSIBLE_PIPELINING(/home/mfaine/development/collections/ansible_collections/nics/utility/ansible.cfg) = True
ANSIBLE_SSH_ARGS(env: ANSIBLE_SSH_ARGS) = -F /home/mfaine/development/collections/ansible_collections/nics/utility/config
COLLECTIONS_PATHS(env: ANSIBLE_COLLECTIONS_PATHS) = ['/home/mfaine/development/collections', '/home/mfaine/.ansible/collections']
COLOR_DEBUG(env: ANSIBLE_COLOR_DEBUG) = white
DEFAULT_FORKS(/home/mfaine/development/collections/ansible_collections/nics/utility/ansible.cfg) = 10
DEFAULT_LOG_PATH(env: ANSIBLE_LOG_PATH) = /var/log/ansible/mfaine/ansible.log
DEFAULT_MANAGED_STR(/home/mfaine/development/collections/ansible_collections/nics/utility/ansible.cfg) = This file is managed by Ansible, all changes will be lost.
DEFAULT_REMOTE_USER(/home/mfaine/development/collections/ansible_collections/nics/utility/ansible.cfg) = bean
DEFAULT_SCP_IF_SSH(env: ANSIBLE_SCP_IF_SSH) = True
DEFAULT_TRANSPORT(/home/mfaine/development/collections/ansible_collections/nics/utility/ansible.cfg) = ssh
DEFAULT_VAULT_PASSWORD_FILE(/home/mfaine/development/collections/ansible_collections/nics/utility/ansible.cfg) = /home/mfaine/development/collections/ansible_collections/nics
HOST_KEY_CHECKING(/home/mfaine/development/collections/ansible_collections/nics/utility/ansible.cfg) = False
INTERPRETER_PYTHON(/home/mfaine/development/collections/ansible_collections/nics/utility/ansible.cfg) = auto_silent
RETRY_FILES_ENABLED(/home/mfaine/development/collections/ansible_collections/nics/utility/ansible.cfg) = False

OS / Environment

Red Hat Enterprise Linux Server release 7.9 (Maipo)

Steps to Reproduce


- name: Manage logical volumes
  community.general.lvol:
    state: "{{ item.state }}"
    active: "{{ item.active | bool }}"
    force: "{{ item.force | default(false) }}"
    lv: "{{ item.lv }}"
    options: "{{ item.options | default(omit) }}"
    pvs: "{{ item.pvs | join(',') }}"
    resizefs: "{{ item.resizefs | bool }}"
    shrink: "{{ item.shrink | bool }}"
    size: "{{ item.size }}"
    vg: "{{ item.vg }}"
    snapshot: "{{ item.snapshot | default(omit) }}"
    thinpool: "{{ item.thinpool | default(omit) }}"
  become: true
  loop: "{{ lvm_logical_volumes | list }}"

The vars looks like this:

lvm_partitions:
  - device: /dev/sdb1
    start: "0%"
    end: "100%"
    flags:
      - lvm
    state: present
    resize: false
    part_type: primary
    fs_type: xfs
    label: gpt
    name: "LVM"
    units: "MiB"

lvm_volume_groups:
  - vg: logs
    pvs:
      - /dev/sdb1
    state: present
    force: false
    pesize: 4
    pvresize: false

lvm_logical_volumes:
  - vg: logs
    lv: data
    pvs:
      - /dev/sdb1
    resizefs: true
    shrink: true
    size: 75%VG
    state: present
    active: true
    force: true
    force_format: false
    fstype: ext4

lvm_mountpoints:
  - src: /dev/logs/data
    path: /var/log/remote/data
    owner: root
    group: root
    mode: '0755'
    state: mounted
    boot: true

Expected Results

I expected the volume to be reduced in size to the size specified

Actual Results

Error msg: "Command does not accept argument /dev/sdb1"

Code of Conduct

ansibullbot commented 3 years ago

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 3 years ago

cc @abulimov @jhoekx @unkaputtbar112 @zigaSRC click here for bot help

russoz commented 3 years ago

Hi @markfaine thanks for reporting this. This error message comes from lvreduce itself, not from the lvol module. If I may ask, what is the rationale for passing the PV when doing a lvreduce, to begin with?

eszense commented 2 years ago

Same issue here.

The invocation for lvextend and lvreduce shares the same code, and lvextend accepts pv as argument while lvreduce doesn't

I have developed a fix by omitting pvs when lvreduce is used instead of lvextend. Shall I make a PR?

felixfontein commented 2 years ago

@eszense PRs are always welcome!

ansibullbot commented 2 years ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help