acl: do not remove all default entries (#32615)

pull/32725/head
Martin Krizek 7 years ago committed by GitHub
parent 39595771fa
commit 714598e91b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -199,9 +199,6 @@ def build_command(module, mode, path, follow, default, recursive, entry=''):
cmd.append('-h') cmd.append('-h')
if default: if default:
if mode == 'rm':
cmd.insert(1, '-k')
else: # mode == 'set' or mode == 'get'
cmd.insert(1, '-d') cmd.insert(1, '-d')
cmd.append(path) cmd.append(path)

@ -17,6 +17,7 @@
- set_fact: - set_fact:
ansible_user: ansible_user ansible_user: ansible_user
ansible_group: ansible_group
ansible_file: /tmp/ansible_file ansible_file: /tmp/ansible_file
ansible_dir: /tmp/ansible_dir ansible_dir: /tmp/ansible_dir
@ -24,6 +25,10 @@
user: user:
name: "{{ ansible_user }}" name: "{{ ansible_user }}"
- name: Create ansible group
group:
name: "{{ ansible_group }}"
- name: Create ansible file - name: Create ansible file
file: file:
path: "{{ ansible_file }}" path: "{{ ansible_file }}"
@ -52,8 +57,8 @@
that: that:
- output|changed - output|changed
- not output|failed - not output|failed
- "'user:ansible_user:r--' in output.acl" - "'user:{{ ansible_user }}:r--' in output.acl"
- "'user:ansible_user:r--' in getfacl_output.stdout_lines" - "'user:{{ ansible_user }}:r--' in getfacl_output.stdout_lines"
############################################################################## ##############################################################################
- name: Obtain the acl for a specific file - name: Obtain the acl for a specific file
acl: acl:
@ -70,12 +75,12 @@
- not output|changed - not output|changed
- not output|failed - not output|failed
- "'user::rw-' in output.acl" - "'user::rw-' in output.acl"
- "'user:ansible_user:r--' in output.acl" - "'user:{{ ansible_user }}:r--' in output.acl"
- "'group::r--' in output.acl" - "'group::r--' in output.acl"
- "'mask::r--' in output.acl" - "'mask::r--' in output.acl"
- "'other::r--' in output.acl" - "'other::r--' in output.acl"
- "'user::rw-' in getfacl_output.stdout_lines" - "'user::rw-' in getfacl_output.stdout_lines"
- "'user:ansible_user:r--' in getfacl_output.stdout_lines" - "'user:{{ ansible_user }}:r--' in getfacl_output.stdout_lines"
- "'group::r--' in getfacl_output.stdout_lines" - "'group::r--' in getfacl_output.stdout_lines"
- "'mask::r--' in getfacl_output.stdout_lines" - "'mask::r--' in getfacl_output.stdout_lines"
- "'other::r--' in getfacl_output.stdout_lines" - "'other::r--' in getfacl_output.stdout_lines"
@ -97,8 +102,8 @@
that: that:
- output|changed - output|changed
- not output|failed - not output|failed
- "'user:ansible_user:r--' not in output.acl" - "'user:{{ ansible_user }}:r--' not in output.acl"
- "'user:ansible_user:r--' not in getfacl_output.stdout_lines" - "'user:{{ ansible_user }}:r--' not in getfacl_output.stdout_lines"
############################################################################## ##############################################################################
- name: Sets default acl for ansible user on ansible dir - name: Sets default acl for ansible user on ansible dir
acl: acl:
@ -119,8 +124,8 @@
that: that:
- output|changed - output|changed
- not output|failed - not output|failed
- "'user:ansible_user:rw-' in output.acl" - "'user:{{ ansible_user }}:rw-' in output.acl"
- "'default:user:ansible_user:rw-' in getfacl_output.stdout_lines" - "'default:user:{{ ansible_user }}:rw-' in getfacl_output.stdout_lines"
############################################################################## ##############################################################################
- name: Cleanup - name: Cleanup
shell: "setfacl -b {{ ansible_dir }}" shell: "setfacl -b {{ ansible_dir }}"
@ -128,7 +133,8 @@
- name: Same as previous but using entry shorthand - name: Same as previous but using entry shorthand
acl: acl:
path: "{{ ansible_dir }}" path: "{{ ansible_dir }}"
entry: "default:user:{{ ansible_user }}:rw-" entry: "user:{{ ansible_user }}:rw-"
default: yes
state: present state: present
register: output register: output
@ -141,13 +147,14 @@
that: that:
- output|changed - output|changed
- not output|failed - not output|failed
- "'user:ansible_user:rw-' in output.acl" - "'user:{{ ansible_user }}:rw-' in output.acl"
- "'default:user:ansible_user:rw-' in getfacl_output.stdout_lines" - "'default:user:{{ ansible_user }}:rw-' in getfacl_output.stdout_lines"
############################################################################## ##############################################################################
- name: Same as previous, to test idempotence - name: Same as previous, to test idempotence
acl: acl:
path: "{{ ansible_dir }}" path: "{{ ansible_dir }}"
entry: "default:user:{{ ansible_user }}:rw-" entry: "user:{{ ansible_user }}:rw-"
default: yes
state: present state: present
register: output register: output
@ -160,6 +167,45 @@
that: that:
- not output|changed - not output|changed
- not output|failed - not output|failed
- "'user:ansible_user:rw-' in output.acl" - "'user:{{ ansible_user }}:rw-' in output.acl"
- "'default:user:ansible_user:rw-' in getfacl_output.stdout_lines" - "'default:user:{{ ansible_user }}:rw-' in getfacl_output.stdout_lines"
############################################################################## ##############################################################################
- name: Cleanup
shell: "setfacl -b {{ ansible_dir }}"
##############################################################################
- name: Set default acls
acl:
path: "{{ ansible_dir }}"
entry: "{{ item }}"
default: yes
state: present
with_items:
- "user:{{ ansible_user }}:rw-"
- "group:{{ ansible_group }}:rw-"
- name: Remove default group ansible_user acl
acl:
path: "{{ ansible_dir }}"
entry: "group:{{ ansible_group }}:rw-"
default: yes
state: absent
register: output
- name: get getfacl output
shell: "getfacl {{ ansible_dir }}"
register: getfacl_output
- name: verify output
assert:
that:
- output|changed
- not output|failed
- "'user::rwx' in getfacl_output.stdout_lines"
- "'group::r-x' in getfacl_output.stdout_lines"
- "'other::r-x' in getfacl_output.stdout_lines"
- "'default:user::rwx' in getfacl_output.stdout_lines"
- "'default:user:{{ ansible_user }}:rw-' in getfacl_output.stdout_lines"
- "'default:group::r-x' in getfacl_output.stdout_lines"
- "'default:mask::rwx' in getfacl_output.stdout_lines"
- "'default:other::r-x' in getfacl_output.stdout_lines"
- "'default:group:{{ ansible_group }}:rw-' not in getfacl_output.stdout_lines"

Loading…
Cancel
Save