• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to set permissions to the files by using Ansible playbook

  • 00:41 lsb_release -a
  • 00:58 vi test.yml
  • 03:31 ansible-playbook test.yml --syntax-check
  • 03:53 ansible-playbook test.yml
  • 04:13 ls -la /
  • 04:36 vi test.yml
  • 06:23 ansible-playbook test.yml --syntax-check
  • 06:37 ansible-playbook test.yml
6742

To Set Permissions to the files by using Ansible playbook

Introduction:

Ansible is a tool that automates the configuration, deployment, and maintenance of applications. The Linux operating system utilizes ownership and permissions for security. Linux systems have three types of users: Owners, Groups, and Others.

Prerequisite:

ansible

Configuration Steps:

Step 1: Check the OS version by using the following command

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

Step 2: Create playbook as test.yml for Creating a file named “Linuxhelp”

root@linuxhelp:~# vi test.yml
- hosts: localhost
  gather_facts: true
  tasks:
  - name: Create a file named Linuxhelp
    file:
       path: /Linuxhelp
       state: touch

Step 3: Check the syntax of the test.yml ansible playbook by using the following command

root@linuxhelp:~# ansible-playbook test.yml --syntax-check

playbook: test.yml

Step 4: Run the test.yml playbook by using the following command

root@linuxhelp:~# ansible-playbook test.yml 

PLAY [localhost] **********************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************
ok: [localhost]

TASK [Create a file named Linuxhelp] **************************************************************************************
changed: [localhost]

PLAY RECAP ****************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Step 5: List the files to view the created file

root@linuxhelp:~# ls -la /
total 1918400
drwxr-xr-x  20 root root       4096 Nov  9 02:48 .
drwxr-xr-x  20 root root       4096 Nov  9 02:48 ..
lrwxrwxrwx   1 root root          7 Sep  8 16:48 bin -> usr/bin
lrwxrwxrwx   1 root root          7 Sep  8 16:48 lib -> usr/lib
lrwxrwxrwx   1 root root          9 Sep  8 16:48 lib32 -> usr/lib32
lrwxrwxrwx   1 root root          9 Sep  8 16:48 lib64 -> usr/lib64
lrwxrwxrwx   1 root root         10 Sep  8 16:48 libx32 -> usr/libx32
-rw-r--r--   1 root root          0 Nov  9 02:47 Linuxhelp
drwx------   2 root root      16384 Sep  8 16:47 lost+found
drwxr-xr-x  35 root root        940 Nov  9 02:42 run

Step 6: Edit the test.yml playbook for Changing the permissions to the file named “Linuxhelp”

root@linuxhelp:~# vi test.yml 
- hosts: localhost
  gather_facts: true
  tasks:
  - name: Create a file named Linuxhelp
    file:
       path: /Linuxhelp
       state: touch
  - name: Changing the permissions	
    file:
       path: /Linuxhelp
       owner: root
       group: linuxhelp
       mode: 0755

Step 7: Again Check the syntax of the test.yml ansible playbook by using the following command

root@linuxhelp:~# ansible-playbook test.yml --syntax-check

playbook: test.yml

Step 8: Run the test.yml playbook by using the following command

root@linuxhelp:~# ansible-playbook test.yml 

PLAY [localhost] **********************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************
ok: [localhost]

TASK [Create a file named Linuxhelp] **************************************************************************************
changed: [localhost]

TASK [Changing the permissions] *******************************************************************************************
changed: [localhost]

PLAY RECAP ****************************************************************************************************************
localhost                  : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Step 9: List the files to view the permissions and ownership changed for the file "Linuxhelp”

root@linuxhelp:~# ls -la /
total 1918400
drwxr-xr-x  20 root root            4096 Nov  9 02:48 .
drwxr-xr-x  20 root root            4096 Nov  9 02:48 ..
lrwxrwxrwx   1 root root               7 Sep  8 16:48 bin -> usr/bin
drwxr-xr-x   4 root root            4096 Nov  3 06:13 boot
lrwxrwxrwx   1 root root               7 Sep  8 16:48 lib -> usr/lib
lrwxrwxrwx   1 root root               9 Sep  8 16:48 lib32 -> usr/lib32
lrwxrwxrwx   1 root root               9 Sep  8 16:48 lib64 -> usr/lib64
lrwxrwxrwx   1 root root              10 Sep  8 16:48 libx32 -> usr/libx32
-rwxr-xr-x   1 root linuxhelp          0 Nov  9 02:57 Linuxhelp
drwx------   2 root root           16384 Sep  8 16:47 lost+found
drwxrwxrwt  18 root root            4096 Nov  9 02:57 tmp
drwxr-xr-x  14 root root            4096 Apr 20  2021 usr
drwxr-xr-x  14 root root            4096 Apr 20  2021 var

By this setting permissions to the files by using Ansible playbook comes to end

Tags:
philippe
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

What is the module used for Linux file management in Ansible?

A

"file" is the module used for Linux file management in Ansible.

Q

For what win_file Module is used?

A

"win_file" is used to create, touch, or remove files or directories.

Q

How to define a number of levels to descend under the "file" module?

A

Use "depth" to define the directory levels

Q

What is the copy module in Ansible?

A

The copy module is used to copy files and folders from the local machine to the remote servers

Q

What does Set_fact do in Ansible?

A

It is used to gather information from your remote hosts.

Related Tutorials in How to set permissions to the files by using Ansible playbook

Related Tutorials in How to set permissions to the files by using Ansible playbook

How to install Meld tool in Ubuntu
How to install Meld tool in Ubuntu
Feb 25, 2017
How to install Dconf-Editor on Ubuntu 18.04
How to install Dconf-Editor on Ubuntu 18.04
Jul 14, 2018
How to install and update OpenSSL on Ubuntu 16.04
How to install and update OpenSSL on Ubuntu 16.04
Mar 9, 2017
How to install GLib 2.0 on Ubuntu 17.04
How to install GLib 2.0 on Ubuntu 17.04
May 22, 2017
How to Install Android Emulator on Ubuntu 20.4.1
How to Install Android Emulator on Ubuntu 20.4.1
Jul 13, 2021
How To Install AnyDesk on Ubuntu 16.04
How To Install AnyDesk on Ubuntu 16.04
Apr 4, 2018
How to install Genymotion 2.12.1 on Ubuntu 18.04
How to install Genymotion 2.12.1 on Ubuntu 18.04
Jul 9, 2018
How to install Timeshift 18.4 on Ubuntu 18.04
How to install Timeshift 18.4 on Ubuntu 18.04
Jul 6, 2018

Related Forums in How to set permissions to the files by using Ansible playbook

Related Forums in How to set permissions to the files by using Ansible playbook

Ubuntu
matthew class=
Failed to enable unit: Refusing to operate on linked unit file sshd.service
Apr 15, 2019
Ubuntu
mason class=
Passwd: You may not view or modify password information for root On Ubuntu 19.04
May 27, 2019
Ubuntu
isaac class=
/etc/apt/sources.list Permission denied
May 18, 2017
Ubuntu
yousuf class=
lsb_release command not working : Debian
Jan 18, 2018
ifconfig command
jackbrookes class=
what is the location of the ifconfig program on your machine?
Jan 4, 2018
Linux
baseer class=
single command to apply setfacl for multiple user at a time
Jan 23, 2018
Ubuntu
mason class=
"E: Package 'php-mcrypt' has no installation candidate" error on Ubuntu 20.4.1
Mar 15, 2021
NFS
luke class=
clnt_create: RPC: Program not registered
Apr 25, 2017

Related News in How to set permissions to the files by using Ansible playbook

Related News in How to set permissions to the files by using Ansible playbook

How To Install Mixxx on Ubuntu 16.04
How To Install Mixxx on Ubuntu 16.04
Oct 11, 2017
Ubuntu 17.04 released with greater expectations
Ubuntu 17.04 released with greater expectations
Apr 15, 2017
Ubuntu Core now available on i.MX6 based TS-4900 thanks to Technologic Systems Inc.
Ubuntu Core now available on i.MX6 based TS-4900 thanks to Technologic Systems Inc.
Mar 1, 2017
Ubuntu 17.10 Artful Aardvark Beta 1 is now here. Download Now
Ubuntu 17.10 Artful Aardvark Beta 1 is now here. Download Now
Sep 2, 2017
Ubuntu Unity is no more: One Linux dream has been axed
Ubuntu Unity is no more: One Linux dream has been axed
Apr 7, 2017
What’s next for Ubuntu Linux Desktop?
What’s next for Ubuntu Linux Desktop?
Apr 11, 2017
Say Hi to Ubuntu's new mascot
Say Hi to Ubuntu's new mascot
Mar 22, 2019
KDE Connect App was removed from Google Play Store and brought back in 24 hours
KDE Connect App was removed from Google Play Store and brought back in 24 hours
Mar 22, 2019
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Luk Van De Looverbosch ?
How to create a root ?

Hello,
How to create root@linuxhelp in Linux Mint 20.1 64-bit ?
Thanks in advance for your reply.
Best regards.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.