Content
Today I worked on an Ansible automation task that involved creating files and configuring Access Control Lists (ACLs) on multiple application servers in the Stratos Datacenter. This task helped me understand how Ansible can automate file management while assigning fine-grained permissions to specific users and groups without changing the file ownership.
๐น What I Learned
- Creating files using the Ansible File module
- Managing Linux Access Control Lists (ACLs) using the ansible.posix.acl module
- Assigning permissions to specific users and groups using ACLs
- Understanding how ACLs extend traditional Linux file permissions
๐น Task Requirement
As per the Nautilus DevOps team requirements, I needed to:
- Create an Ansible playbook:
/home/thor/ansible/playbook.yml
using the existing inventory file:
/home/thor/ansible/inventory
The playbook should perform the following tasks:
- On App Server 1, create an empty file:
/opt/security/blog.txt
and grant read (r) permission to group tony using ACL.
- On App Server 2, create an empty file:
/opt/security/story.txt
and grant read and write (rw) permissions to user steve using ACL.
- On App Server 3, create an empty file:
/opt/security/media.txt
and grant read and write (rw) permissions to group banner using ACL.
The playbook must execute successfully using:
ansible-playbook -i inventory playbook.yml
without passing any additional arguments.
๐น Steps I Followed
1. Navigated to the Working Directory
I first moved to the Ansible working directory on the jump host.
cd /home/thor/ansible
This directory already contained the required inventory file.
2. Verified the Inventory
I checked the existing inventory.
cat inventory
Output:
stapp01 ansible_host=stapp01 ansible_ssh_pass=Ir0nM@n ansible_user=tony
stapp02 ansible_host=stapp02 ansible_ssh_pass=Am3ric@ ansible_user=steve
stapp03 ansible_host=stapp03 ansible_ssh_pass=BigGr33n ansible_user=banner
This inventory contains the SSH connection details for all three application servers.
Since the inventory does not define any host groups, I used the individual hostnames (stapp01, stapp02, and stapp03) in the playbook.
3. Verified the Initial State
Before creating the playbook, I connected to one of the application servers to verify that the target file did not already exist.
ssh steve@stapp02
Navigated to the target directory.
cd /opt/security
Checked the contents.
ls
Output:
(no files)
Observation
This confirmed that the required file had not yet been created.
After verifying the initial state, I returned to the jump host to create the playbook.
4. Created the Playbook
I created the playbook.
vi playbook.yml
Added the following content:
---
- name: Create blog.txt on App Server 1 and configure ACL
hosts: stapp01
become: true
tasks:
- name: Ensure /opt/security/blog.txt exists
ansible.builtin.file:
path: /opt/security/blog.txt
state: touch
- name: Grant read permission to group tony
ansible.posix.acl:
path: /opt/security/blog.txt
entity: tony
etype: group
permissions: r
state: present
- name: Create story.txt on App Server 2 and configure ACL
hosts: stapp02
become: true
tasks:
- name: Ensure /opt/security/story.txt exists
ansible.builtin.file:
path: /opt/security/story.txt
state: touch
- name: Grant read and write permissions to user steve
ansible.posix.acl:
path: /opt/security/story.txt
entity: steve
etype: user
permissions: rw
state: present
- name: Create media.txt on App Server 3 and configure ACL
hosts: stapp03
become: true
tasks:
- name: Ensure /opt/security/media.txt exists
ansible.builtin.file:
path: /opt/security/media.txt
state: touch
- name: Grant read and write permissions to group banner
ansible.posix.acl:
path: /opt/security/media.txt
entity: banner
etype: group
permissions: rw
state: present
Saved the file.
๐น Understanding the Playbook
Target Hosts
Each play targets a specific application server.
hosts: stapp01
Similarly, the remaining plays target stapp02 and stapp03.
Since the inventory contains individual hosts rather than groups, each play is executed on a single server.
Privilege Escalation
become: true
Creating files inside /opt/security and modifying ACLs require administrative privileges.
Using become: true allows Ansible to execute each task with root privileges.
File Module
ansible.builtin.file
The File module manages files and directories on remote systems.
In this task, it creates an empty file using:
state: touch
This behaves similarly to the Linux touch command.
If the file already exists, Ansible updates its timestamp without recreating it, making the task idempotent.
ACL Module
ansible.posix.acl
The ACL module manages Linux Access Control Lists.
Unlike traditional Linux permissions, ACLs allow permissions to be assigned to individual users or groups without changing the file owner or primary group.
Important parameters used in this task:
entity:
Specifies the user or group receiving the permission.
etype:
Defines whether the entity is a user or a group.
permissions:
Specifies the permission to assign.
Examples:
permissions: r
permissions: rw
state: present
Ensures that the ACL entry exists.
Since Ansible is idempotent, running the playbook multiple times will not create duplicate ACL entries.
5. Executed the Playbook
Ran:
ansible-playbook -i inventory playbook.yml
Output:
PLAY RECAP
stapp01 : ok=3 changed=2 failed=0
stapp02 : ok=3 changed=2 failed=0
stapp03 : ok=3 changed=2 failed=0
๐น Understanding the Output
Gathering Facts
Before executing any tasks, Ansible collected system information from each managed host.
File Creation
The File module successfully created the required files on each application server.
The status:
changed
indicates that the files were created successfully.
ACL Configuration
The ACL module added the required permissions for the specified users and groups.
Each ACL entry was successfully applied to the corresponding file.
Play Recap
ok=3
changed=2
failed=0
Meaning:
- Three tasks completed successfully on each host.
- Two tasks modified each application server.
- No failures occurred during execution.
6. Validated the Configuration
After the playbook completed successfully, I connected to one application server.
ssh steve@stapp02
Navigated to the target directory.
cd /opt/security
Listed the files.
ls -la
Output:
-rw-rw-r--+ 1 root root 0 Jun 29 15:23 story.txt
Observation
The file was:
- Created successfully.
- Owned by the root user.
- Displayed a + symbol, indicating that extended ACLs were configured.
To inspect the ACL entries, I used:
getfacl story.txt
This confirmed that the required ACL permissions had been applied.
๐น Verification
โ
Created blog.txt, story.txt, and media.txt
โ
Files are owned by the root user
โ Configured ACL permissions for the required users and groups
โ Successfully executed the playbook on all application servers
โ
Verified file creation using ls -la
โ
Verified ACL entries using getfacl
๐น My Understanding
This task helped me understand how Linux Access Control Lists (ACLs) provide more flexible permission management than traditional file permissions. By using the ansible.posix.acl module together with the ansible.builtin.file module, I was able to automate both file creation and fine-grained permission assignment across multiple servers while keeping the playbook idempotent and easy to maintain.
๐น What I Found Interesting
I found it interesting that Linux ACLs allow permissions to be granted to specific users or groups without changing the file owner or primary group. Using Ansible, I could create files and configure different ACL permissions on multiple application servers simultaneously with a single playbook, making system administration both efficient and consistent.
๐ Full notes: GitHub link
- #managing-acls-using-ansible
- #acl
- #access
- #linux
- #access-control-list
- #acl-module
- #ansible
- #ansible-playbook
- #ansible-module
- #ansible-adhoc
- #ansible-automation
- #ansible-project
- #ansible-inventory-file
- #ansible-acl-module
- #ansible-article
- #ansible-devops
- #devops
- #devops-articles
- #devops-journey
- #devopscommunity
- #devops-trends
- #devops-tools
- #devops-engineer
- #devopsculture
- #devopsjourney
- #devopsproject
- #100daysofdevops
About the author
- Iโm currently working in DevOps and documenting my learning journey along the way. From CI/CD pipelines to cloud and containers, Iโm exploring how modern systems are built and deployed. This blog is where I share what I learn, break down concepts in simple terms, and track my progress. Learning one concept at a time, and trying to apply it practically.
Comments
Join the discussionNo comments yet. Be the first to comment.
100_days_of_devops
Documenting my 100 Days of DevOps journey with hands-on practice from KodeKloud, along with notes, commands, and mini projects