mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fixes #4516 file module: check prev_state earlier and use that if state is not specified
This commit is contained in:
parent
d478eaa6a5
commit
f4b59fe285
1 changed files with 25 additions and 14 deletions
|
@ -142,7 +142,7 @@ def main():
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
state = dict(choices=['file','directory','link','hard','touch','absent'], default='file'),
|
state = dict(choices=['file','directory','link','hard','touch','absent'], default=None),
|
||||||
path = dict(aliases=['dest', 'name'], required=True),
|
path = dict(aliases=['dest', 'name'], required=True),
|
||||||
recurse = dict(default='no', type='bool'),
|
recurse = dict(default='no', type='bool'),
|
||||||
force = dict(required=False,default=False,type='bool'),
|
force = dict(required=False,default=False,type='bool'),
|
||||||
|
@ -171,6 +171,30 @@ def main():
|
||||||
pass
|
pass
|
||||||
module.exit_json(path=path, changed=False, appears_binary=appears_binary)
|
module.exit_json(path=path, changed=False, appears_binary=appears_binary)
|
||||||
|
|
||||||
|
prev_state = 'absent'
|
||||||
|
|
||||||
|
if os.path.lexists(path):
|
||||||
|
if os.path.islink(path):
|
||||||
|
prev_state = 'link'
|
||||||
|
elif os.path.isdir(path):
|
||||||
|
prev_state = 'directory'
|
||||||
|
elif os.stat(path).st_nlink > 1:
|
||||||
|
prev_state = 'hard'
|
||||||
|
else:
|
||||||
|
# could be many other things, but defaulting to file
|
||||||
|
prev_state = 'file'
|
||||||
|
|
||||||
|
if prev_state is not None and state is None:
|
||||||
|
if not params.get('src', None):
|
||||||
|
# idempotent exit if state is not specified
|
||||||
|
module.exit_json(path=path, changed=False)
|
||||||
|
else:
|
||||||
|
# src is defined, need to process other operations
|
||||||
|
state = prev_state
|
||||||
|
elif state is None:
|
||||||
|
# set default state to file
|
||||||
|
state = 'file'
|
||||||
|
|
||||||
# source is both the source of a symlink or an informational passing of the src for a template module
|
# source is both the source of a symlink or an informational passing of the src for a template module
|
||||||
# or copy module, even if this module never uses it, it is needed to key off some things
|
# or copy module, even if this module never uses it, it is needed to key off some things
|
||||||
|
|
||||||
|
@ -190,19 +214,6 @@ def main():
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
prev_state = 'absent'
|
|
||||||
|
|
||||||
if os.path.lexists(path):
|
|
||||||
if os.path.islink(path):
|
|
||||||
prev_state = 'link'
|
|
||||||
elif os.path.isdir(path):
|
|
||||||
prev_state = 'directory'
|
|
||||||
elif os.stat(path).st_nlink > 1:
|
|
||||||
prev_state = 'hard'
|
|
||||||
else:
|
|
||||||
# could be many other things, but defaulting to file
|
|
||||||
prev_state = 'file'
|
|
||||||
|
|
||||||
recurse = params['recurse']
|
recurse = params['recurse']
|
||||||
|
|
||||||
if recurse and state == 'file' and prev_state == 'directory':
|
if recurse and state == 'file' and prev_state == 'directory':
|
||||||
|
|
Loading…
Reference in a new issue