ansible-role-yedit icon indicating copy to clipboard operation
ansible-role-yedit copied to clipboard

Multiple simultaneous yml accesses

Open mikasaari opened this issue 8 years ago • 1 comments

Hi,

There could be 'lock' option in yedit which would lock the file if there are multiple simultaneous accesses to the file.

I tested code below and seems to be working. Though I didn't make any exhaustive testing for it.

    module = AnsibleModule(
        argument_spec=dict(
            state=dict(default='present', type='str',
                       choices=['present', 'absent', 'list']),
            debug=dict(default=False, type='bool'),
            src=dict(default=None, type='str'),
            content=dict(default=None),
            content_type=dict(default='dict', choices=['dict', 'str']),
            key=dict(default='', type='str'),
            value=dict(),
            value_type=dict(default='', type='str'),
            update=dict(default=False, type='bool'),
            append=dict(default=False, type='bool'),
            index=dict(default=None, type='int'),
            curr_value=dict(default=None, type='str'),
            curr_value_format=dict(default='yaml', choices=['yaml', 'json', 'str'], type='str'),
            backup=dict(default=True, type='bool'),
            lock=dict(default=False, type='bool'),
        ),
        mutually_exclusive=[["curr_value", "index"], ['update', "append"]],
        required_one_of=[["content", "src"]],

        supports_check_mode=True,
    )
    state = module.params['state']

    yamlfile = Yedit(filename=module.params['src'], backup=module.params['backup'])

    if module.params['lock'] == True:
        lock_file = open(yamlfile.filename + ".yedit_lock", "w")
        fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX)

mikasaari avatar Sep 19 '16 11:09 mikasaari

Thanks for your contribution :) Can you please put it into a pull request (including the missing import statements) so we can take a look at it properly?

https://help.github.com/articles/about-pull-requests/

luto avatar Sep 19 '16 14:09 luto