Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lvol module is not idempotent #29201

Closed
ansibot opened this issue Sep 10, 2017 · 33 comments
Closed

lvol module is not idempotent #29201

ansibot opened this issue Sep 10, 2017 · 33 comments
Labels
affects_1.9 This issue/PR affects Ansible v1.9 bot_closed bug This issue/PR relates to a bug. collection:community.general collection Related to Ansible Collections work has_pr This issue has an associated PR. module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community. system System category

Comments

@ansibot
Copy link
Contributor

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

Issue Type:

Bug Report

Component Name

lvol module

Ansible Version:

ansible 1.9.0.1

Environment:

Management Station OS: Ubuntu 12.04.04
Managed OS: Centos 6.5 (i386)

Summary:

'lvol' module is not idempotent so every time I re-run a playbook with no changes to the variabiles file, it fails.

Steps To Reproduce:

Create a playbook with this vars file:

vgs:
  - vgname: vgOracle

    pvs:
      - vde

    lvs:
      - lvname: lvOraRoot
        mntp: /oracle
        lvsize: 1
        fstype: ext4

      - lvname: lvOraClient
        mntp: /oracle/client
        lvsize: 1
        fstype: ext4

and this task:

     - name: filesystem | create logical volumes
       lvol: lv={{ item[1].lvname}} vg={{ item[0].vgname }} size="{{ (((item[1].lvsize*5/100) + item[1].lvsize)*1024)|int }}m" state=present
       with_subelements:
         - vgs
         - lvs

On the first run, everything is ok but on the second one, the 'lvol' task triggers this bad error:

failed: [server1] => (item=({'vgname': u'vgOracle', 'pvs': ['vde']}, {'mntp': '/oracle', 'lvsize': 1, 'lvname': 'lvOraRoot', 'fstype': 'ext4'})) => {"failed": true, "item": [{"pvs": ["vde"], "vgname": "vgOracle"}, {"fstype": "ext4", "lvname": "lvOraRoot", "lvsize": 1, "mntp": "/oracle"}]}
msg: Sorry, no shrinking of lvOraRoot without force=yes.
failed: [server1] => (item=({'vgname': u'vgOracle', 'pvs': ['vde']}, {'mntp': '/oracle/client', 'lvsize': 1, 'lvname': 'lvOraClient', 'fstype': 'ext4'})) => {"failed": true, "item": [{"pvs": ["vde"], "vgname": "vgOracle"}, {"fstype": "ext4", "lvname": "lvOraClient", "lvsize": 1, "mntp": "/oracle/client"}]}
msg: Sorry, no shrinking of lvOraClient without force=yes.

FATAL: all hosts have already failed -- aborting

It seems that the 'lvol' module wants to shrink the logical volume even if i didn't change the size in my vars. (I also tried to set the force=yes but it crashes miserably...maybe i have to fill another bug)
It works as expected if i increase the values of the 'lvsize' in the vars file.

As a work-around, I invoke the 'lvcreate' by using the 'command' (idempotency is provided by the 'creates' arguments) :

     - name: filesystem | create logical volumes
       command: lvcreate {{ item[0].vgname }} -n {{ item[1].lvname}} -L"{{ (((item[1].lvsize*5/100) + item[1].lvsize)*1024|int) }}m"
       args:
        creates: "/dev/{{ item[0].vgname }}/{{ item[1].lvname}}"
       with_subelements:
         - vgs
         - lvs
Expected Results:

I expected the 'lvol' module to be idempotency-aware (as all others ansible modules)

Actual Results:

Idemopotency is not enforced.

Copied from original issue: ansible/ansible-modules-extras#428

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

I forgot to tell that if I use the patched module found at https://github.com/psa/ansible/commit/00e19d1780fdec57e6c51f727f29472d64b51f05, it works as expected

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

Hi @angystardust:

Thanks for submitting this bug report. Apologies for taking so long to triage it. :) Since this bug has been open for a while, we would appreciate if you can verify if you are still seeing the reported behavior in the latest version.

If you are seeing the reported behavior, just let us know and we will leave the bug open and notify the module maintainer.

If you are no longer seeing the reported behavior, please let us know and we will close the bug report.

Thanks! :)

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

If this is stil an issue, it's because the lvol module is assuming that an operation on an existing LV is intended to change the size (which is only the case if the size argument differs from the actual LV's size), and lvreduce (my guess is the module is checking size <= the current LV's size to decide to use reduce) returns failure when the LV is already the requested size.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

@robynbergeron, this is still an issue for me 😞

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

@analogbyte See if #1382 magically fixes this. The check to see if size different was incorrect, I added a int() wrapper which should make it work now. Give it a shot

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

@angystardust

Do you still have the commit of psa/ansible@00e19d1, it is gone.

Could you please send me a copy?

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

this problem is still not fixed in latest ansible v2.0.1 and v2.1

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

I think your issue is fixed with #2220

You can influence the shrink behaviour using shrink=no or shrink=yes. This was added by #2135.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

This is a problem for me if I use 100%FREE, the first time work, the second I get "Sorry, no shrinking of 'volume name' to 0 permitted.", this was working in the version 2.0 but now in 2.1 doesn't work.

And "shrink=" do not exists in 2.1.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

@pega2k I would suggest downloading the module and putting it in your library/ directory until you switch to v2.2... If that would fail to work as well, let us know !

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

@dagwieers it works using shrink=no.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

@pega2k Thanks for reporting back !

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

Glad to see someone found this option usefull :)

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

It works around the bug, but I think there is still a weird assumption about the %FREE option. It seems that every time the module is run, the %FREE is taken from the remaining space. So every single time it would run, your volume size would be different. 90% free the first time you get the remaining 90% of space. Second time you get a tiny VM that is 90% of the remaining 10% of space. Then up, then down, etc... In reality the math should probably work out so that it subtracts the current size of the volume from the used space and then does the % check. So if you say you want 90% free, and no changes are made between two runs, you'd get the exact same size both times.

In the mean time, we'll just vendor the module until 2.2 comes out and set shring=no.

@ansibot

This comment has been minimized.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

@dagwieers I am curious if there are any plans to set a flag such that if the lv exists, leave it be, if it doesn't create it using size specified? I am sure there are cases we'd want to give it space if some existed, but this may not always be the case. I cannot upgrade to 2.2 yet, so shrink=no is not an option for me, and I am not sure where to get this module that makes the creation idempotent with 100%FREE. Thanks for any help.

@ansibot

This comment has been minimized.

@ansibot ansibot added affects_1.9 This issue/PR affects Ansible v1.9 bug_report needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 10, 2017
@ansibot

This comment has been minimized.

3 similar comments
@ansibot

This comment has been minimized.

@ansibot

This comment has been minimized.

@ansibot

This comment has been minimized.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

just upgraded to 2.2.0.2 and confirm 100%FREE lvols are still causing this error

@ansibot

This comment has been minimized.

@ansibot
Copy link
Contributor Author

ansibot commented Sep 10, 2017

From @angystardust on 2015-04-27T00:15:27Z

Coming here from #3527, i don't agree with @j2sol, the math is right here.. if we use %FREE, semantically for me that means '% of remaining free space', if you want a 'percentage of the total space of the vg', use %VG, which just works, and is idempotent. I don't know when %VG was added, but it works for me with 2.1.1 and 2.2.1.

@ansibot ansibot added module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 10, 2017
@bryan-croft
Copy link

I've been working around the non-idempotence of the %FREE thing by just adding a conditional like:

lvol: vg=vg1 lv=demo size=100%FREE
when:
  - ansible_lvm['vgs']['vg1']['free_g'] != "0"

@it-kombinat
Copy link

it-kombinat commented Oct 17, 2017

Hello, Is this also valid for Ansible 2.3.1 an what is the best way for a work around?

@ymartin59
Copy link
Contributor

I would like to implement such a check like ansible_lvm['vgs']['vg1']['free_g'] but testing LV current size. Is there any documentation about this ansible_lvm variable structure/content ?

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@dglinder
Copy link
Contributor

dglinder commented Aug 8, 2018

Any update on this?

@dagwieers
Copy link
Contributor

dagwieers commented Aug 9, 2018

@angystardust To me this seems to be a rounding error. If you provide a size which doesn't map on a multiple of the extent-size, the LVM tools will round it up or down to the nearest possible value. If you run it again, the new value may be higher or lower, and this will cause an error like yours.

If you would like to fix this, you need to get the extent-size, and use modulo extent-size on the size value, then use this value for the number of extents. Contributions are welcome.

waiting_on_contributor

And BTW the fact that using 100%FREE (or X%FREE) is not idempotent is pretty obvious. If you base your size on the availability of the free space, a subsequent run will declare a different value from the previous run.

@dagwieers dagwieers added the waiting_on_contributor This would be accepted but there are no plans to actively work on it. label Aug 9, 2018
@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Sep 18, 2018
@ansibot ansibot added needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 4, 2018
@ansibot ansibot removed the needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) label Nov 10, 2018
@ansibot ansibot added the system System category label Feb 17, 2019
@danielmotaleite
Copy link

Using ansible 2.8.3 AND shrink: no and it still fails:

- name: Create cache pool logical volume if not exists
  lvol:
    vg: vg
    lv: cache_vol
    size: 100%VG 
    shrink: no
    opts: "--type cache-pool"
    pvs: /dev/nvme2n1,/dev/nvme3n1
fatal: [worker-staging-b03]: FAILED! => {
    "changed": false
}

MSG:

Logical Volume cache_vol could not be extended. Not enough free space left (12583004.0m required / 0.0m available)
 ansible --version
ansible 2.8.3
  config file = /home/dleite/git/ansible/ansible.cfg
  configured module search path = [u'/home/dleite/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15+ (default, Nov 27 2018, 23:36:35) [GCC 7.3.0]

Even worse, i understand that 100%FREE is no idempotent, but 100%PVS or 100%VG should be idempotent always, even with shrink=yes, as the value do not change

@ansibot ansibot added collection Related to Ansible Collections work collection:community.general needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md has_pr This issue has an associated PR. labels Apr 29, 2020
@ansibot
Copy link
Contributor Author

ansibot commented Aug 17, 2020

Thank you very much for your interest in Ansible. Ansible has migrated much of the content into separate repositories to allow for more rapid, independent development. We are closing this issue/PR because this content has been moved to one or more collection repositories.

For further information, please see:
https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_1.9 This issue/PR affects Ansible v1.9 bot_closed bug This issue/PR relates to a bug. collection:community.general collection Related to Ansible Collections work has_pr This issue has an associated PR. module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community. system System category
Projects
None yet
Development

No branches or pull requests

8 participants