Create or Remove files and directories - RHCE.pdf

support8872 176 views 15 slides Oct 09, 2024
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

Slides on how to create or remove files and directories on remote host - Part of RHCE syllabus


Slide Content

Create or Remove files and
directories

●Used for managing files and directories in Ansible

●Attributes
○path: Specifies the full path of the directory/file
○owner: Sets the owner
○group: Sets the group
○mode: Sets the permissions of the directory/file
○state: Ensures that the path is a directory/file

●Link: file module— Ansible Documentation








File Module

●Verify that remote host is reachable using ping module
Command: ansible all -m ping

Create a directory on Remote Host

●Execute the playbook
Command: ansible-playbook <file-name> .yml

●Verify that directory is created on remote host
Command: ls /<directory-path> | grep <directory-name>

Create a file on Remote Host

●Execute the playbook on control node
Command: ansible-playbook <file-name> .yml

●On the remote host verify whether the file is created
Command: ls /<directory-path> | grep <file-name>

Remove a File on Remote Host

●Execute the playbook on control node
Command: ansible-playbook <file-name> .yml

●Verify whether the file is removed from the directory on the remote host
Command: ls /<directory-path> | grep <file-name>

Remove a directory on Remote Host

●Execute the playbook on control node
Command: ansible-playbook <file-name> .yml

●Verify whether the directory is removed on remote host
Command: ls /<directory_path> | grep <directory_name>