Merge recursive file permission setting on directories
This commit is contained in:
parent
8db504fba8
commit
e44412101b
2 changed files with 23 additions and 4 deletions
|
@ -133,7 +133,7 @@ def main():
|
||||||
image = dict(required=True),
|
image = dict(required=True),
|
||||||
kernel = dict(),
|
kernel = dict(),
|
||||||
count = dict(default='1'),
|
count = dict(default='1'),
|
||||||
monitoring = dict(choices=BOOLEANS, default=False),
|
monitoring = dict(choices=BOOLEANS, default=False),
|
||||||
ramdisk = dict(),
|
ramdisk = dict(),
|
||||||
wait = dict(choices=BOOLEANS, default=False),
|
wait = dict(choices=BOOLEANS, default=False),
|
||||||
ec2_url = dict(aliases=['EC2_URL']),
|
ec2_url = dict(aliases=['EC2_URL']),
|
||||||
|
@ -177,8 +177,8 @@ def main():
|
||||||
try:
|
try:
|
||||||
res = ec2.run_instances(image, key_name = key_name,
|
res = ec2.run_instances(image, key_name = key_name,
|
||||||
min_count = count,
|
min_count = count,
|
||||||
max_count = count,
|
max_count = count,
|
||||||
monitoring_enabled = monitoring,
|
monitoring_enabled = monitoring,
|
||||||
security_groups = [group],
|
security_groups = [group],
|
||||||
instance_type = instance_type,
|
instance_type = instance_type,
|
||||||
kernel_id = kernel,
|
kernel_id = kernel,
|
||||||
|
|
21
library/file
21
library/file
|
@ -113,6 +113,12 @@ options:
|
||||||
description:
|
description:
|
||||||
- accepts only C(default) as value. This will restore a file's SELinux context
|
- accepts only C(default) as value. This will restore a file's SELinux context
|
||||||
in the policy. Does nothing if no default value is available.
|
in the policy. Does nothing if no default value is available.
|
||||||
|
recurse:
|
||||||
|
required: false
|
||||||
|
default: no
|
||||||
|
choices: [ "yes", "no" ]
|
||||||
|
description:
|
||||||
|
- recursively set the specified file attributes (applies only to state=directory)
|
||||||
examples:
|
examples:
|
||||||
- code: "file: path=/etc/foo.conf owner=foo group=foo mode=0644"
|
- code: "file: path=/etc/foo.conf owner=foo group=foo mode=0644"
|
||||||
description: Example from Ansible Playbooks
|
description: Example from Ansible Playbooks
|
||||||
|
@ -133,6 +139,7 @@ def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
state = dict(choices=['file','directory','link','absent'], default='file'),
|
state = dict(choices=['file','directory','link','absent'], default='file'),
|
||||||
path = dict(aliases=['dest', 'name'], required=True),
|
path = dict(aliases=['dest', 'name'], required=True),
|
||||||
|
recurse = dict(default='no', choices=BOOLEANS)
|
||||||
),
|
),
|
||||||
add_file_common_args=True,
|
add_file_common_args=True,
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
|
@ -202,12 +209,24 @@ def main():
|
||||||
module.exit_json(path=path, changed=changed)
|
module.exit_json(path=path, changed=changed)
|
||||||
|
|
||||||
elif state == 'directory':
|
elif state == 'directory':
|
||||||
|
|
||||||
if prev_state == 'absent':
|
if prev_state == 'absent':
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
changed = module.set_directory_attributes_if_different(file_args, changed)
|
changed = module.set_directory_attributes_if_different(file_args, changed)
|
||||||
|
recurse = module.boolean(params['recurse'])
|
||||||
|
if recurse:
|
||||||
|
for root,dirs,files in os.walk( file_args['path'] ):
|
||||||
|
for dir in dirs:
|
||||||
|
dirname=os.path.join(root,dir)
|
||||||
|
tmp_file_args = file_args.copy()
|
||||||
|
tmp_file_args['path']=dirname
|
||||||
|
changed = module.set_directory_attributes_if_different(tmp_file_args, changed)
|
||||||
|
for file in files:
|
||||||
|
filename=os.path.join(root,file)
|
||||||
|
tmp_file_args = file_args.copy()
|
||||||
|
tmp_file_args['path']=filename
|
||||||
|
changed = module.set_file_attributes_if_different(tmp_file_args, changed)
|
||||||
module.exit_json(path=path, changed=changed)
|
module.exit_json(path=path, changed=changed)
|
||||||
|
|
||||||
elif state == 'link':
|
elif state == 'link':
|
||||||
|
|
Loading…
Reference in a new issue