Ansible Permissions, ACLs and File Modes
File modes in YAML have a trap, and it is not quite where most guidance says it is. A leading zero is fine; omitting it is not, because YAML then reads a decimal number and the resulting permissions are nothing like what you wrote. This proves it three ways, then covers recursion, ACLs for what mode cannot express, and where SELinux would sit on a RHEL host.
Automating Administration Guide 35 of 45 Intermediate
- OSUbuntu 26.04 LTS
- ansible-core2.20.1
- Python3.14.4
- TimeAbout 16 min
This lab is Ubuntu 26.04 and EX294 is a RHEL exam. the file and ansible.posix.acl modules are identical on both. The difference is mandatory access control: RHEL has SELinux and the ansible.posix.selinux, seboolean and sefcontext modules that go with it, while Ubuntu uses AppArmor and ansible_facts['selinux'] reports disabled.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| ANS-CTL01 | 192.168.0.36 | Ubuntu 26.04 LTS | Ansible Control Node | 2 Core | 3 GB | 50 GB |
| ANS-A01 | 192.168.0.37 | Ubuntu 26.04 LTS | Managed Node (group: web) | 2 Core | 3 GB | 50 GB |
This guide includes
Use this when a file mode written in YAML does not produce the permissions you meant. This matters because the trap is not quite where most guidance says it is - and ACLs are what you need once three subjects are not enough.
- writing the same intent four ways, and finding where the octal trap actually is
- setting owner, group and recursion
- using ACLs for what a mode cannot express, beyond owner, group and other
- reading what would be SELinux on RHEL, and what this host reports instead
Before you start
- A control node configured as shown in the first step.
- The session installs
acl, creates/opt/permsand a usercarol, and removes both.
-
The configuration this guide assumes
-
The octal trap is not where you think
-
Owner, group and recursion
-
ACLs for what mode cannot express
-
What would be SELinux on RHEL