AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible Set File Permissions 755: chmod with file Module Guide

By Luca Berton · Published 2024-01-01 · Category: troubleshooting

How to set file permissions with Ansible file module. Add execute permission (755, 644, 600), manage ownership, and apply permissions recursively.

How to Add Execute Permission 755 on Linux file with Ansible? I'm going to show you a live Playbook and some simple Ansible code. I'm Luca Berton and welcome to today's episode of Ansible Pilot.

Ansible Add Execute Permission • ansible.builtin.file • Manage files and file properties

Today we're talking about the Ansible module file. The full name is ansible.builtin.file, which means that is part of the collection of modules "builtin" with ansible and shipped with it. It's a module pretty stable and out for years. It works in a different variety of operating systems. It manages files and file properties. For Windows targets, use the ansible.windows.win_file module instead.

Main Parameters • path _string_ (dest, name) - file path • owner _string_ - user • group _string_ - group • mode _raw_ - Ex: '0644' or 'u=rw,g=r,o=r' • state _string_ - file, absent, directory, hard, link, touch • setype/seuser/selevel - SELinux

This module has some parameters to perform any tasks. The only required is "path", where you specify the filesystem path of the file you're going to edit. The parameter "owner" set the user that should own the file/directory. The parameter "group" set the group that should own the file/directory. The parameter "mode" set the permissions in the UNIX way of the file/directory. The state defines the type of object we are modifying, the default is "file" but we could handle also directories, hard links, symlinks, or only update the access time with the "touch" option. Let me also highlight that we could also specify the SELinux properties.

Linksansible.builtin.file

## Playbook How to Add Execute Permission 755 file on Linux with Ansible Playbook. I'm going to show you how to set the chmod +x of an example.sh Linux file with Ansible.

code • file_permission.yml • example.sh

execution

idempotency

before execution

after execution

code with ❤️ in GitHub

Conclusion

Now you know how to Add Execute Permission 755 for a file on Linux.

Set 755 (Execute Permission)

Common Permission Patterns

Set Permissions on Multiple Files

Using fileglob

Recursive Permissions

Symbolic Mode

Separate File/Directory Permissions

Permission Reference

| Octal | Symbolic | Meaning | |-------|----------|---------| | 0755 | rwxr-xr-x | Executable by all, writable by owner | | 0644 | rw-r--r-- | Readable by all, writable by owner | | 0600 | rw------- | Owner only (keys, secrets) | | 0700 | rwx------ | Owner only, executable | | 0775 | rwxrwxr-x | Group writable + executable | | 0640 | rw-r----- | Owner write, group read | | 0440 | r--r----- | Read only (sudoers) |

FAQ

Why quote mode as '0755'?

YAML interprets unquoted 0755 as decimal 493. Always quote: mode: '0755'

How do I check current permissions?

What about setuid/setgid/sticky bit?

Set 755 (rwxr-xr-x)

Common Permission Modes

Symbolic Mode

Set Owner and Group

Recursive Permissions

Different Permissions for Files vs Dirs

Set Permissions on Copy

Multiple Files

Special Bits

FAQ

Why quote the mode ('0755' not 0755)?

YAML interprets unquoted 0755 as octal integer (493). Quoting ensures it's passed as a string and interpreted correctly.

How to check current permissions?

recurse only works on directories?

recurse: true requires state: directory. It sets the same permissions on ALL files and subdirectories — use find + command for different file/dir permissions.

Related ArticlesAnsible Inventory Guideansible.builtin.file GuideAnsible for Windows Guide

Category: troubleshooting

Watch the video: Ansible Set File Permissions 755: chmod with file Module Guide — Video Tutorial

Browse all Ansible tutorials · AnsiblePilot Home