Ansible: When 'file_regex` is set, only operate on files#8425
Merged
mildas merged 1 commit intoComplianceAsCode:stabilization-v0.1.61from Mar 25, 2022
Conversation
In rule 'file_permissions_library_dirs', when navigating '/lib', the
task finds hardlinks and trips on them:
"failed: [rhel9] (item={'path': '/lib/locale/en_AG/LC_COLLATE', 'mode':
'0644' .... "msg": "src is required for creating new hardlinks"}"
This ensure that the Ansible task acts on regular files, and not on
the hardlink or symlinks.
mildas
approved these changes
Mar 25, 2022
Contributor
mildas
left a comment
There was a problem hiding this comment.
Tested on E8 ansible playbooks. Previously, the playbook exited with return code 2. Now, there are no failed tasks and return code is 0. LGTM, thank you
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
file_owner,file_groupwonerandfile_permissionsensure that the Ansible task acts on regular files whenfile_regexis set.The task fails when trying to change hardlinks.
failed: [rhel9] (item={'path': '/lib/locale/en_AG/LC_COLLATE', 'mode': '0644', 'isdir': False, 'ischr': False, 'isblk': False, 'isreg': True, 'isfifo': False, 'islnk': False, 'issock': False, 'uid': 0, 'gid': 0, 'size': 2586930, 'inode': 33735145, 'dev': 64768, 'nlink': 18, 'atime': 1648146988.540588, 'mtime':1633112517.0, 'ctime': 1637841862.7420955, 'gr_name': 'root', 'pw_name': 'root', 'wusr': True, 'rusr': True, 'xusr': False, 'wgrp': False, 'rgrp': True, 'xgrp': False, 'woth': False, 'roth': True, 'xoth': False, 'isuid': False, 'isgid': False}) => {"ansible_loop_var": "item", "changed": false, "item": {"atime": 1648146988.540588, "ctime": 1637841862.7420955, "dev": 64768, "gid": 0, "gr_name": "root", "inode": 33735145, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": false, "isreg": true, "issock": false, "isuid": false, "mode": "0644", "mtime": 1633112517.0, "nlink": 18, "path": "/lib/locale/en_AG/LC_COLLATE", "pw_name": "root", "rgrp": true, "roth": true, "rusr": true, "size": 2586930, "uid": 0, "wgrp": false, "woth": false, "wusr": true, "xgrp": false, "xoth": false, "xusr": false}, "msg": "src is required for creating new hardlinks"}state: fileso that the task acts on regular files.Rationale:
file_permissions_library_dirstravels down/libit finds hardlinks that cause the Ansible task to fail.The task should act on the actual file, not the hardlink, so lets skip the hardlinks.