2017-11-02 16:55:42 +01:00
|
|
|
# (c) 2017, Martin Krizek <mkrizek@redhat.com>
|
|
|
|
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
- name: Create ansible user
|
|
|
|
user:
|
2018-01-15 13:21:25 +01:00
|
|
|
name: "{{ test_user }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
|
2017-11-09 10:31:33 +01:00
|
|
|
- name: Create ansible group
|
|
|
|
group:
|
2018-01-15 13:21:25 +01:00
|
|
|
name: "{{ test_group }}"
|
2017-11-09 10:31:33 +01:00
|
|
|
|
2017-11-02 16:55:42 +01:00
|
|
|
- name: Create ansible file
|
|
|
|
file:
|
2018-01-15 13:21:25 +01:00
|
|
|
path: "{{ test_file }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
state: touch
|
|
|
|
|
|
|
|
- name: Create ansible dir
|
|
|
|
file:
|
2018-01-15 13:21:25 +01:00
|
|
|
path: "{{ test_dir }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
state: directory
|
|
|
|
##############################################################################
|
|
|
|
- name: Grant ansible user read access to a file
|
|
|
|
acl:
|
2018-01-15 13:21:25 +01:00
|
|
|
path: "{{ test_file }}"
|
|
|
|
entity: "{{ test_user }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
etype: user
|
|
|
|
permissions: r
|
|
|
|
state: present
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: get getfacl output
|
2019-10-11 19:40:19 +02:00
|
|
|
shell: "getfacl {{ test_file | quote }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
register: getfacl_output
|
|
|
|
|
|
|
|
- name: verify output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- output is changed
|
|
|
|
- output is not failed
|
2018-01-15 13:21:25 +01:00
|
|
|
- "'user:{{ test_user }}:r--' in output.acl"
|
|
|
|
- "'user:{{ test_user }}:r--' in getfacl_output.stdout_lines"
|
2017-11-02 16:55:42 +01:00
|
|
|
##############################################################################
|
|
|
|
- name: Obtain the acl for a specific file
|
|
|
|
acl:
|
2018-01-15 13:21:25 +01:00
|
|
|
path: "{{ test_file }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: get getfacl output
|
2019-10-11 19:40:19 +02:00
|
|
|
shell: "getfacl {{ test_file | quote }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
register: getfacl_output
|
|
|
|
|
|
|
|
- name: verify output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- output is not changed
|
|
|
|
- output is not failed
|
2017-11-02 16:55:42 +01:00
|
|
|
- "'user::rw-' in output.acl"
|
2018-01-15 13:21:25 +01:00
|
|
|
- "'user:{{ test_user }}:r--' in output.acl"
|
2017-11-02 16:55:42 +01:00
|
|
|
- "'group::r--' in output.acl"
|
|
|
|
- "'mask::r--' in output.acl"
|
|
|
|
- "'other::r--' in output.acl"
|
|
|
|
- "'user::rw-' in getfacl_output.stdout_lines"
|
2018-01-15 13:21:25 +01:00
|
|
|
- "'user:{{ test_user }}:r--' in getfacl_output.stdout_lines"
|
2017-11-02 16:55:42 +01:00
|
|
|
- "'group::r--' in getfacl_output.stdout_lines"
|
|
|
|
- "'mask::r--' in getfacl_output.stdout_lines"
|
|
|
|
- "'other::r--' in getfacl_output.stdout_lines"
|
|
|
|
##############################################################################
|
|
|
|
- name: Removes the acl for ansible user on a specific file
|
|
|
|
acl:
|
2018-01-15 13:21:25 +01:00
|
|
|
path: "{{ test_file }}"
|
|
|
|
entity: "{{ test_user }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
etype: user
|
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: get getfacl output
|
2019-10-11 19:40:19 +02:00
|
|
|
shell: "getfacl {{ test_file | quote }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
register: getfacl_output
|
|
|
|
|
|
|
|
- name: verify output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- output is changed
|
|
|
|
- output is not failed
|
2018-01-15 13:21:25 +01:00
|
|
|
- "'user:{{ test_user }}:r--' not in output.acl"
|
|
|
|
- "'user:{{ test_user }}:r--' not in getfacl_output.stdout_lines"
|
2017-11-02 16:55:42 +01:00
|
|
|
##############################################################################
|
|
|
|
- name: Sets default acl for ansible user on ansible dir
|
|
|
|
acl:
|
2018-01-15 13:21:25 +01:00
|
|
|
path: "{{ test_dir }}"
|
|
|
|
entity: "{{ test_user }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
etype: user
|
|
|
|
permissions: rw
|
|
|
|
default: yes
|
|
|
|
state: present
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: get getfacl output
|
2019-10-11 19:40:19 +02:00
|
|
|
shell: "getfacl {{ test_dir | quote }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
register: getfacl_output
|
|
|
|
|
|
|
|
- name: verify output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- output is changed
|
|
|
|
- output is not failed
|
2018-01-15 13:21:25 +01:00
|
|
|
- "'user:{{ test_user }}:rw-' in output.acl"
|
|
|
|
- "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines"
|
2017-11-02 16:55:42 +01:00
|
|
|
##############################################################################
|
|
|
|
- name: Cleanup
|
2019-10-11 19:40:19 +02:00
|
|
|
shell: "setfacl -b {{ test_dir | quote }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
##############################################################################
|
|
|
|
- name: Same as previous but using entry shorthand
|
|
|
|
acl:
|
2018-01-15 13:21:25 +01:00
|
|
|
path: "{{ test_dir }}"
|
|
|
|
entry: "user:{{ test_user }}:rw-"
|
2017-11-09 10:31:33 +01:00
|
|
|
default: yes
|
2017-11-02 16:55:42 +01:00
|
|
|
state: present
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: get getfacl output
|
2019-10-11 19:40:19 +02:00
|
|
|
shell: "getfacl {{ test_dir | quote }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
register: getfacl_output
|
|
|
|
|
|
|
|
- name: verify output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- output is changed
|
|
|
|
- output is not failed
|
2018-01-15 13:21:25 +01:00
|
|
|
- "'user:{{ test_user }}:rw-' in output.acl"
|
|
|
|
- "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines"
|
2017-11-02 16:55:42 +01:00
|
|
|
##############################################################################
|
|
|
|
- name: Same as previous, to test idempotence
|
|
|
|
acl:
|
2018-01-15 13:21:25 +01:00
|
|
|
path: "{{ test_dir }}"
|
|
|
|
entry: "user:{{ test_user }}:rw-"
|
2017-11-09 10:31:33 +01:00
|
|
|
default: yes
|
2017-11-02 16:55:42 +01:00
|
|
|
state: present
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: get getfacl output
|
2019-10-11 19:40:19 +02:00
|
|
|
shell: "getfacl {{ test_dir | quote }}"
|
2017-11-02 16:55:42 +01:00
|
|
|
register: getfacl_output
|
|
|
|
|
|
|
|
- name: verify output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- output is not changed
|
|
|
|
- output is not failed
|
2018-01-15 13:21:25 +01:00
|
|
|
- "'user:{{ test_user }}:rw-' in output.acl"
|
|
|
|
- "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines"
|
2017-11-02 16:55:42 +01:00
|
|
|
##############################################################################
|
2017-11-09 10:31:33 +01:00
|
|
|
- name: Cleanup
|
2019-10-11 19:40:19 +02:00
|
|
|
shell: "setfacl -b {{ test_dir | quote }}"
|
2017-11-09 10:31:33 +01:00
|
|
|
##############################################################################
|
|
|
|
- name: Set default acls
|
|
|
|
acl:
|
2018-01-15 13:21:25 +01:00
|
|
|
path: "{{ test_dir }}"
|
2017-11-09 10:31:33 +01:00
|
|
|
entry: "{{ item }}"
|
|
|
|
default: yes
|
|
|
|
state: present
|
|
|
|
with_items:
|
2018-01-15 13:21:25 +01:00
|
|
|
- "user:{{ test_user }}:rw-"
|
|
|
|
- "group:{{ test_group }}:rw-"
|
2017-11-09 10:31:33 +01:00
|
|
|
|
2018-01-15 13:21:25 +01:00
|
|
|
- name: Remove default group test_user acl
|
2017-11-09 10:31:33 +01:00
|
|
|
acl:
|
2018-01-15 13:21:25 +01:00
|
|
|
path: "{{ test_dir }}"
|
|
|
|
entry: "group:{{ test_group }}:rw-"
|
2017-11-09 10:31:33 +01:00
|
|
|
default: yes
|
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: get getfacl output
|
2019-10-11 19:40:19 +02:00
|
|
|
shell: "getfacl {{ test_dir | quote }}"
|
2017-11-09 10:31:33 +01:00
|
|
|
register: getfacl_output
|
|
|
|
|
|
|
|
- name: verify output
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- output is changed
|
|
|
|
- output is not failed
|
2017-11-09 10:31:33 +01:00
|
|
|
- "'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"
|
2018-01-15 13:21:25 +01:00
|
|
|
- "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines"
|
2017-11-09 10:31:33 +01:00
|
|
|
- "'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"
|
2018-01-15 13:21:25 +01:00
|
|
|
- "'default:group:{{ test_group }}:rw-' not in getfacl_output.stdout_lines"
|