Slides on how to create or remove files and directories on remote host - Part of RHCE syllabus
Size: 625.5 KB
Language: en
Added: Oct 09, 2024
Slides: 15 pages
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>