Skip to content

Ansible: When 'file_regex` is set, only operate on files#8425

Merged
mildas merged 1 commit intoComplianceAsCode:stabilization-v0.1.61from
yuumasato:file_permissions_library_dirs-hardlink-issue
Mar 25, 2022
Merged

Ansible: When 'file_regex` is set, only operate on files#8425
mildas merged 1 commit intoComplianceAsCode:stabilization-v0.1.61from
yuumasato:file_permissions_library_dirs-hardlink-issue

Conversation

@yuumasato
Copy link
Copy Markdown
Member

@yuumasato yuumasato commented Mar 25, 2022

Description:

  • In templates file_owner, file_groupwoner and file_permissions ensure that the Ansible task acts on regular files when file_regex is 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"}

  • This adds state: file so that the task acts on regular files.

Rationale:

  • When rule file_permissions_library_dirs travels down /lib it 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.
[root@localhost ~]# ls -i /lib/locale/en_AG/LC_COLLATE
33735145 /lib/locale/en_AG/LC_COLLATE

[root@localhost ~]# 
[root@localhost ~]# find / -inum 33735145
/usr/lib/locale/en_AG/LC_COLLATE
/usr/lib/locale/en_AU.utf8/LC_COLLATE
/usr/lib/locale/en_BW.utf8/LC_COLLATE
/usr/lib/locale/en_DK.utf8/LC_COLLATE
/usr/lib/locale/en_GB.utf8/LC_COLLATE
/usr/lib/locale/en_HK.utf8/LC_COLLATE
/usr/lib/locale/en_IE.utf8/LC_COLLATE
/usr/lib/locale/en_IL/LC_COLLATE
/usr/lib/locale/en_IN/LC_COLLATE
/usr/lib/locale/en_NG/LC_COLLATE
/usr/lib/locale/en_NZ.utf8/LC_COLLATE
/usr/lib/locale/en_PH.utf8/LC_COLLATE
/usr/lib/locale/en_SC.utf8/LC_COLLATE
/usr/lib/locale/en_SG.utf8/LC_COLLATE
/usr/lib/locale/en_US.utf8/LC_COLLATE
/usr/lib/locale/en_ZA.utf8/LC_COLLATE
/usr/lib/locale/en_ZM/LC_COLLATE
/usr/lib/locale/en_ZW.utf8/LC_COLLATE

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.
@yuumasato yuumasato added the bugfix Fixes to reported bugs. label Mar 25, 2022
@yuumasato yuumasato added this to the 0.1.61 milestone Mar 25, 2022
@yuumasato yuumasato requested a review from mildas March 25, 2022 10:27
@github-actions
Copy link
Copy Markdown

Start a new ephemeral environment with changes proposed in this pull request:

Open in Gitpod

@mildas mildas self-assigned this Mar 25, 2022
Copy link
Copy Markdown
Contributor

@mildas mildas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mildas mildas merged commit bd9afd3 into ComplianceAsCode:stabilization-v0.1.61 Mar 25, 2022
@yuumasato yuumasato deleted the file_permissions_library_dirs-hardlink-issue branch March 25, 2022 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes to reported bugs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants