Repository: ansible/ansible

Issue:
lvg: Allow pesize to be in kilobytes
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and devel branch are affected too.
Always add information AFTER of these html comments.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Feature Idea

##### COMPONENT NAME
<!---
Insert below this comment the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->
lvg
##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.3.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/sac/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Mar 14 2018, 13:36:31) [GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]

```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
None.

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
N/A
##### SUMMARY
<!--- Explain the problem briefly -->
lvg allows the values for pesize only in megabytes which is a limitation since for JBODS and RAID disks the optimal values are 1280k. Should allow sizes to be in kilobytes or decimal values

Same for pv_options values. Allowing decimal values would be more appropriate. 

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
Try to create a vg with decimal value for pesize
<!--- Paste example playbooks or commands between quotes below -->
```yaml
---
# tasks file for backend-setup
- name: Create volume group on the nodes
  lvg:
     state: present
     vg: foo.vg
     pvs: /dev/sdb
     pv_options: "--dataalignment 1.5"
     pesize: 1.5
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
PLAY [Setting up backend] ***********************************************************************************************************

TASK [glusterfs.infra/roles/backend-setup : Create volume group on the nodes] *******************************************************
fatal: [10.70.43.249]: FAILED! => {"changed": false, "msg": "argument pesize is of type <type 'float'> and we were unable to convert to int: <type 'float'> cannot be converted to an int"}
fatal: [10.70.43.142]: FAILED! => {"changed": false, "msg": "argument pesize is of type <type 'float'> and we were unable to convert to int: <type 'float'> cannot be converted to an int"}
        to retry, use: --limit @/home/sac/work/scratch/roles/call_infra.retry

PLAY RECAP **************************************************************************************************************************
10.70.43.142               : ok=0    changed=0    unreachable=0    failed=1   
10.70.43.249               : ok=0    changed=0    unreachable=0    failed=1   
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/system/lvg.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/system/lvg.py)

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](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @abulimov
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/system/lvg.py b/lib/ansible/modules/system/lvg.py
--- a/lib/ansible/modules/system/lvg.py
+++ b/lib/ansible/modules/system/lvg.py
@@ -32,7 +32,9 @@
     - The module will take care of running pvcreate if needed.
   pesize:
     description:
-    - The size of the physical extent in megabytes. Must be a power of 2.
+    - The size of the physical extent. pesize must be a power of 2, or
+      multiple of 128KiB. Since version 2.6, pesize can be optionally suffixed
+      by a UNIT (k/K/m/M/g/G), default unit is megabyte.
     default: 4
   pv_options:
     description:
@@ -63,6 +65,12 @@
     pvs: /dev/sda1
     pesize: 32
 
+- name: Create a volume group on top of /dev/sdb with physical extent size = 128KiB
+  lvg:
+    vg: vg.services
+    pvs: /dev/sdb
+    pesize: 128K
+
 # If, for example, we already have VG vg.services on top of /dev/sdb1,
 # this VG will be extended by /dev/sdc5.  Or if vg.services was created on
 # top of /dev/sda5, we first extend it with /dev/sdb1 and /dev/sdc5,
@@ -124,7 +132,7 @@ def main():
         argument_spec=dict(
             vg=dict(type='str', required=True),
             pvs=dict(type='list'),
-            pesize=dict(type='int', default=4),
+            pesize=dict(type='str', default=4),
             pv_options=dict(type='str', default=''),
             vg_options=dict(type='str', default=''),
             state=dict(type='str', default='present', choices=['absent', 'present']),
@@ -200,7 +208,7 @@ def main():
                     else:
                         module.fail_json(msg="Creating physical volume '%s' failed" % current_dev, rc=rc, err=err)
                 vgcreate_cmd = module.get_bin_path('vgcreate')
-                rc, _, err = module.run_command([vgcreate_cmd] + vgoptions + ['-s', str(pesize), vg] + dev_list)
+                rc, _, err = module.run_command([vgcreate_cmd] + vgoptions + ['-s', pesize, vg] + dev_list)
                 if rc == 0:
                     changed = True
                 else:


Test patch: