mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-11 15:15:26 +01:00
Compare commits
2 commits
03e9ed4c58
...
2cbd5b93fb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cbd5b93fb | ||
|
|
624c15166d |
3 changed files with 36 additions and 1 deletions
|
|
@ -226,6 +226,7 @@ import tempfile
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
import errno
|
import errno
|
||||||
|
import traceback
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
|
@ -482,7 +483,8 @@ def readfile(module, filename):
|
||||||
return f.read()
|
return f.read()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e.errno == errno.EACCES:
|
if e.errno == errno.EACCES:
|
||||||
module.fail_json(msg="Permission denied on file or path for authorized keys file: {}".format(filename))
|
module.fail_json(msg="Permission denied on file or path for authorized keys file: %s" % filename,
|
||||||
|
exception=traceback.format_exc())
|
||||||
elif e.errno == errno.ENOENT:
|
elif e.errno == errno.ENOENT:
|
||||||
return ''
|
return ''
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
---
|
||||||
|
# -------------------------------------------------------------
|
||||||
|
# check permissions
|
||||||
|
|
||||||
|
- name: Create a file that is not accessible
|
||||||
|
ansible.builtin.file:
|
||||||
|
state: touch
|
||||||
|
path: "{{ output_dir | expanduser }}/file_permissions"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0000'
|
||||||
|
|
||||||
|
- name: Try to delete a key from an unreadable file
|
||||||
|
ansible.posix.authorized_key:
|
||||||
|
user: root
|
||||||
|
key: "{{ dss_key_basic }}"
|
||||||
|
state: absent
|
||||||
|
path: "{{ output_dir | expanduser }}/file_permissions"
|
||||||
|
register: result
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Assert that the key deletion has failed
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result.failed == True
|
||||||
|
|
||||||
|
- name: Remove the file
|
||||||
|
ansible.builtin.file:
|
||||||
|
state: absent
|
||||||
|
path: "{{ output_dir | expanduser }}/file_permissions"
|
||||||
|
|
@ -34,3 +34,6 @@
|
||||||
|
|
||||||
- name: Test for specifying key as a path
|
- name: Test for specifying key as a path
|
||||||
ansible.builtin.import_tasks: check_path.yml
|
ansible.builtin.import_tasks: check_path.yml
|
||||||
|
|
||||||
|
- name: Test for permission denied files
|
||||||
|
ansible.builtin.import_tasks: check_permissions.yml
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue